- 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 01:01 PM
Remove the word Date in this line
var myDate = new GlideDateTime(Date);
var myDate = new GlideDateTime();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2022 02:38 PM
I receive this when i changed it.
Actual format: 2018-06-20 10:26:34 AM EDT
Changed format: 2/01/2022 1970-01-01 22:34:20
This is not what i was looking for. Is it possible to change only the data format to mm/dd/yyyy?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2022 02:44 PM
Sorry, try this:
var myDate = new GlideDateTime(inTime);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2022 02:51 PM
I get the same.
Actual format: 2017-07-25 04:37:48 PM EDT
Changed format: 7/25/2017 1970-01-01 20:37:48
in process of changing the date format, the time is displaying as wrong. It should be the same as in "actual format" time.