- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 08:04 AM
I have a script that is grabbing an SLA record's date/time variable to put in a notification. I've come to discover that whenever a date/time is applied to .toString(), 4 hours is being added. But the same date/time displays correctly when using the getDisplayValue() function of date/time.
var sla = new GlideRecord('task_sla');
sla.addQuery('sys_id','[my SLA definition's sys_id]');
sla.query();
if (sla.next()) {
var gdt = new GlideDateTime(sla.[my variable name]);
gs.print(gdt.getDisplayValue());
gs.print(gdt.toString());
}
This sample code displays the two values:
Can anyone explain what is happening here, why toString() adds 4 hours?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 09:06 AM
Hi @CBlan2021 ,
GlideDateTime - toString()
Returns the date and time value stored by the GlideDateTime object in the internal format, yyyy-MM-dd HH:mm:ss, and the system time zone, UTC by default. This method is equivalent to getValue().
GlideDateTime - getDisplayValue()
Gets the date and time value in the current user's display format and time zone.
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 08:10 AM - edited 07-19-2024 08:11 AM
Hi there,
Just a case of the time difference between your local setting and the actual system time. In your case 4 hours I guess.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 09:06 AM
Hi @CBlan2021 ,
GlideDateTime - toString()
Returns the date and time value stored by the GlideDateTime object in the internal format, yyyy-MM-dd HH:mm:ss, and the system time zone, UTC by default. This method is equivalent to getValue().
GlideDateTime - getDisplayValue()
Gets the date and time value in the current user's display format and time zone.
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.