- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2021 09:50 AM
developer.servicenow.com says that the getDisplayValue() returns: 'The date and time in the user's format and time zone. Keep in mind when designing business rules or script includes that this method may return values in different formats for different users.'
We have this code in a script include which gets invoked by a business rule. We are setting the time zone based on the asset location and retrieving the date with getDisplayValue() to get the date/time in the desired time zone. For a couple of dates we received a different date format (the time zone is fine).
Example:
var gdt = new GlideDateTime(current.sys_created_on);
var tz = Packages.java.util.TimeZone.getTimeZone('America/New_York');
gdt.setTZ(tz);
gdt.getDisplayValue();
getDisplayValue() returns most of the time the date in the format '2021-04-22 11:12:13' ((yyyy-MM-dd HH:mm:ss) and sometimes '04-22-2021 11:12:13' (MM-dd-yyyy HH:mm:ss).
Could someone please explain why is this happening and what can we do to enforce a specific date format?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2021 09:59 AM
Hi,
To get the specific format can use,
for example
var gd = gdt.getLocalDate();
var gt = gdt.getLocalTime();
gs.addInfoMessage(gd.getByFormat('dd MMM yyyy') + gt.getByFormat(' HH:mm:ss'));
Please mark Correct✅/helpful???? if applicable, thanks!!
Aman

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2021 09:59 AM
Hi,
To get the specific format can use,
for example
var gd = gdt.getLocalDate();
var gt = gdt.getLocalTime();
gs.addInfoMessage(gd.getByFormat('dd MMM yyyy') + gt.getByFormat(' HH:mm:ss'));
Please mark Correct✅/helpful???? if applicable, thanks!!
Aman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2021 11:48 AM
Thank you Aman!