How to display Email Template variable from datetime to date?

rp1
Tera Expert

I'm setting up an email template that has the following in the message - 

This task completion is due on: ${complete_by} 

 

The problem is ${complete_by} comes out as a datetime reference.  How do I get it to only display the date?

 

Current Value

This task completion is due on:  2024-06-14 11:34:55 EDT

 

Expected Value

This task completion is due on:  2024-06-14

1 ACCEPTED SOLUTION

Rampriya-S
Tera Guru
Tera Guru

@rp1 

You can go with email script for extracting the date.

Email script :

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var gdt = new GlideDateTime(current.complete_by);
    var date = gdt.getLocalDate();
    template.print(date);
})(current, template, email, email_action, event);
and call the script like this :
Completed date: ${mail_script:completeDate}
 
Please mark helpful if you accept the solution!!
 
 

 

Best,
Rampriya S

View solution in original post

1 REPLY 1

Rampriya-S
Tera Guru
Tera Guru

@rp1 

You can go with email script for extracting the date.

Email script :

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var gdt = new GlideDateTime(current.complete_by);
    var date = gdt.getLocalDate();
    template.print(date);
})(current, template, email, email_action, event);
and call the script like this :
Completed date: ${mail_script:completeDate}
 
Please mark helpful if you accept the solution!!
 
 

 

Best,
Rampriya S