Remove Time stamp from the updated field

shabbir9
Tera Contributor

Hi Team,

i am using sys_updated_on field in notification but time stamp is coming when i am using ${sys_updated_on} like this "2023-08-22 12:42:51" i want to remove time from this i have created mail script for this but its not working sharing the script can anyone help me in the script 

 

var updated = current.sys_updated_on;
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
template.print(updated.replace(dateRE, ''));
})(current, template, email, email_action, event);
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@shabbir9 

you can use this in email script

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
var gdt = new GlideDateTime(current.sys_updated_on);
var date = gdt.getLocalDate();
template.print(date);
})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Shruti
Mega Sage
Mega Sage
var updated = current.sys_updated_on;
updated = updated.split(" ");
var date = updated[0];
template.print(date);

Najmuddin Mohd
Mega Sage

Hello @shabbir9 ,

You can use OOB GlideDate() functionality.

var updatedValue = current.getValue('sys_updated_on');
var newUpdatedValue = new GlideDate('updatedValue');
template.print(newUpdatedValue);

If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.

Vaibhav_Nikam
Tera Guru
Hi @shabbir9   
 
var date = current.sys_updated_on.split(" ");    //split the date with the 1 empty space
        template.print(date[0]);
 

If my response finds helpful, please indicate its helpfulness by selecting Accept as Solution and Helpful.

Thanks,

Vaibhav Nikam

Ankur Bawiskar
Tera Patron
Tera Patron

@shabbir9 

you can use this in email script

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
var gdt = new GlideDateTime(current.sys_updated_on);
var date = gdt.getLocalDate();
template.print(date);
})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader