- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 05:01 AM
How to change the date format form 2018-07-20 07:37:35 to 20/07/2018 08:37:35.
I have created script include and client script for UTC end field. UTC end will display the GMT date and time automatically when we select the Incident End date and time. But here when I select the Incident date, UTC end date and time is displaying in different format. please can somebody help on how to display the date format in 20/07/2018 08:37:35.
Client Script:
var ga = new GlideAjax('PGIncidentAJAX');
ga.addParam('sysparm_name', 'getGMT');
ga.addParam('sysparm_date_time', newValue);
ga.getXML(processResponse);
function processResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_utc_end', answer);
}
Server Script:
var PGIncidentAJAX = Class.create();
PGIncidentAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGMT: function(){
var dt = this.getParameter('sysparm_date_time');
var gmt = new GlideDateTime();
// gmt.setStringParameter(dt.getByFormat("dd/MM/yyyy"));
gmt.setDisplayValue(dt);
return gmt;
},
type: 'PGIncidentAJAX'
});
Solved! Go to Solution.
- Labels:
-
Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 11:13 AM
I test below in my Dev instance and worked.
var PGIncidentAJAX = Class.create();
PGIncidentAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGMT: function(){
var dt = this.getParameter('sysparm_date_time');
var gdt = new GlideDateTime();
gdt.setDisplayValue(dt);
var date = gdt.getValue().split(' ');
var dateonly = new GlideDate();
dateonly.setValue(date[0]);
var last = dateonly.getByFormat('dd/MM/yyyy') + " " + date[1];
return last;
},
type: 'PGIncidentAJAX'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 08:49 AM
The important thing to remember about ServiceNow is that internally, all dates and times are stored as UTC. It's only when it displays it to a human in a field that the timezone is applied (or in a script if you use getDisplayValue()).
Similarly, if you use setDisplayValue() it is stripping off the timezone to save a UTC value. If you do something like this, you are introducing a timezone offset issue and either losing or gaining time.
var gdt = new GlideDateTime(); //current time/date object in UTC
current.start_time = gdt.getDisplayValue(); // WRONG! getDisplayValue() has a TZ applied,
// start_time is a UTC value -
// you've just made an offset error
Similarly,
var gdt = new GlideDateTime();
current.start_time.setDisplayValue(gdt.getValue()); // WRONG!!!
You're getting a UTC value from gdt and then telling start_time "here comes a value with a timezone, be sure to strip off the system time zone when you save it".
Proper example:
var gdt = new GlideDateTime();
current.start_time = gdt.getValue();
or
var gdt = new GlideDateTime();
current.start_time.setDisplayValue(gdt.getDisplayValue());
See how they match? 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 09:13 AM
It is working all i need is the format to be changed
getGMT: function(){
var dt = this.getParameter('sysparm_date_time');
var gdt = new GlideDateTime();
gdt.setDisplayvalue(dt.getDisplayValue());
return gdt;
},
change the date format form 2018-07-20 07:37:35 to 20/07/2018 08:37:35.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 09:33 AM
you can do
var longDateTime = gdt.getByFormat('dd/MM/yyyy hh:mm:ss');
return longDateTime;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 10:00 AM
Mike that is not displaying any date on load, can you please help me more with script part, my scripting knowledge is not good so please

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 10:34 AM
Only way I can think of is to split and return
var gdt = new GlideDateTime();
gdt.setValue(dt.getDisplayValue());
var date = gdt.getValue().split(' ');
var dateonly = new GlideDate();
dateonly.setValue(date[0]);
var last = dateonly.getByFormat('dd/MM/yyyy') + " " + date[1];
return last;