Glide Date Time toString adds 4 hours?

CBlan2021
Tera Contributor

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:

CBlan2021_0-1721401436481.png

Can anyone explain what is happening here, why toString() adds 4 hours?

1 ACCEPTED SOLUTION

SN_Learn
Kilo Patron
Kilo Patron

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.

Note: Referring to the GlideDateTime object directly returns the date and time value in the GMT time zone.
 
Source is ServiceNow Doc: GlideDateTime - Global 
 
 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

2 REPLIES 2

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

SN_Learn
Kilo Patron
Kilo Patron

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.

Note: Referring to the GlideDateTime object directly returns the date and time value in the GMT time zone.
 
Source is ServiceNow Doc: GlideDateTime - Global 
 
 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.