Start a conversation

Extract only date or time from date and time field

If you want to use a part of a date and time field (i.e. the date only, or the time only), you can use the following templates. Replace your_datetime_variable with your own variable name.

To extract a date from a date and time field:

var splitted_datetime = '{your_datetime_variable}'.split(';');
if(/^((0?[1-9]|[12][0-9]|3[01])[-](0?[1-9]|1[012])[-](19|20)?[0-9]{2})*$/.test(splitted_datetime[0])){
splitted_datetime[0];
} else {
"Date has not been filled in";
}


To extract the time from a date and time field:

var splitted_datetime = '{your_datetime_variable}'.split(';');
if(/^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/.test(splitted_datetime[1])){
splitted_datetime[1];
} else if(/^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/.test(splitted_datetime[0])){
splitted_datetime[0];
} else {
"Time has not been filled in";
}
Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Castor Support Team

  2. Posted