Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

GlideDateTime issue: Setting the datetime with a script, adds 1 hour in the record's datetime field

Smith Johnson
Kilo Sage

Hello,

I would like to ask for some help working with GlideDateTimes.

I have the following script that I try in scripts - background. I try to create a record in a custom table, and populate the u_start and u_end fields.

 var start = new GlideDateTime("2025-01-01 00:00:00");
 var end = new GlideDateTime("2025-01-01 23:59:59");
 var deadlineGr = new GlideRecord('u_deadlines');
 deadlineGr.initialize();
 deadlineGr.setValue('u_start', start);
 deadlineGr.setValue('u_end', end);
 deadlineGr.insert();


However, even if I set start "2025-01-01 00:00:00", I see that when the record is created one hour is added (01/01/2025 01:00:00). The same applies for end date, I see one hour added (02/01/2025 00:59:59 instead of  2025-01-01 23:59:59).

SmithJohnson_0-1762336798695.png
What is going wrong here? How can I see 01/01/2025 00:00:00 and 01/01/2025 23:59:59 for start and end respectively?

Thank you,
Smith.

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Smith Johnson 

it's because of timezone.

try this

 var start = new GlideDateTime("2025-01-01 00:00:00");
 var end = new GlideDateTime("2025-01-01 23:59:59");
 var deadlineGr = new GlideRecord('u_deadlines');
 deadlineGr.initialize();
 deadlineGr.setDisplayValue('u_start', start);
 deadlineGr.setDisplayValue('u_end', end);
 deadlineGr.insert();

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Smith Johnson 

it's because of timezone.

try this

 var start = new GlideDateTime("2025-01-01 00:00:00");
 var end = new GlideDateTime("2025-01-01 23:59:59");
 var deadlineGr = new GlideRecord('u_deadlines');
 deadlineGr.initialize();
 deadlineGr.setDisplayValue('u_start', start);
 deadlineGr.setDisplayValue('u_end', end);
 deadlineGr.insert();

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader