How to format a date and time data type field in a WorkFlow email

Would you like to know how to format the Date and time fields that you send via WF email? Or how to send only the Date or only the Time?

Open the Workflow, set up everything to send the email and use this JavaScript:

for Date and Time:

${doo.model.nameOfTheField.value ? new Date(doo.model.nameOfTheField.value + 'Z').toLocaleString('cs-CZ', { timeZone: 'Europe/Prague' }) : ''} 

For Time only:

${doo.model.nameOfTheField.value ? new Date(doo.model.nameOfTheField.value + 'Z').toLocaleTimeString('cs-CZ', { timeZone: 'Europe/Prague' }) : ''} 

For Date only:

 ${doo.model.nameOfTheField.value ? new Date(doo.model.nameOfTheField.value + 'Z').toLocaleDateString('cs-CZ', { timeZone: 'Europe/Prague' }) : ''} 

Please modify the highlighted parts of the script to the name of the field with the date according to your application and modify to the time zone you prefer.

${doo.model.nameOfTheField.value ? new Date(doo.model.nameOfTheField.value + 'Z').toLocaleString('cs-CZ', { timeZone: 'Europe/Prague' }) : ''}

If you are not sure what the name of a field is, press the Fields button, select the field you want and the name will be written out, see picture:

If you are not sure what Time zone to choose, go to Edit application section, Advanced settings and check the Application time zone

That’s it! Simple and fast :slight_smile:

Have a nice day.
With kind regards,
Soňa

Hi,

I used code for DATE only

${doo.model["DOC_dueDate"].value ? new Date(doo.model["DOC_dueDate"].value + 'Z').toLocaleDateString('cs-CZ', { timeZone: 'Europe/Prague' }) : ''} 

and it doesn’t work. Just got error:

Custom user Javascript error (check the console for more details): Invalid regular expression flags

What’s wrong?

Hi,
I have tested the expression and it seems to be working.
The only problem I had was hidden formatting. When I copied text from this page, it added some formatting string into the expression. I needed to delete whole editor (ctrl+a, ctrl+x). Copy text to notepad++ and them copy the plain text back into the email.
I hope this help.
Regards
Michal

Thanks, that helps. :slight_smile: