- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2022 11:19 AM
Hi,
I am trying to change only date format in my datetime field in a notification. For this i am using an email script.
Here is the current format : 2-1-2022 11:21:56 AM EDT, i want it to be changed to 2/1/2022 11:21:56 AM EDT
I dont want to make any changes to time format, but i couldnt achieve it, below is the code i tried.
(function runMailScript(current, template, email, email_action,event) {
var openedAt = current.opened_at;
template.print(convertTime(openedAt));
function convertTime(inTime) {
if (inTime != '') {
var myDate = new GlideDateTime(Date);
var time = myDate.getTime();
return myDate.getDate().getByFormat("M/dd/yyyy") + ' ' + time;
}
return '';
}
})(current, template, email, email_action, event);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2022 03:08 PM
Do you have your system set up so that it displays EDT? If so, you should be able to add .getDisplayValue() after .getTime to display it.
function convertTime(inTime) {
if (inTime != '') {
var myDate = new GlideDateTime(inTime);
var time = myDate.getTime().getDisplayValue();
return myDate.getDate().getByFormat("M/dd/yyyy") + ' ' + time;
}
return '';
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2022 03:08 PM
Do you have your system set up so that it displays EDT? If so, you should be able to add .getDisplayValue() after .getTime to display it.
function convertTime(inTime) {
if (inTime != '') {
var myDate = new GlideDateTime(inTime);
var time = myDate.getTime().getDisplayValue();
return myDate.getDate().getByFormat("M/dd/yyyy") + ' ' + time;
}
return '';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2022 01:35 PM
This helped me, so thank you!
There is even a better solution for the formatted time return I found while poking around.
var time = myDate.getUserFormattedLocalTime();
This ensures that even if the system isn't formatted on way or another it will get all the correct for local time.