- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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).
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
