Glide Schedule and TimeZone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 11:06 AM - edited ‎02-18-2025 11:07 AM
When using a schedule and calculating the duration between a start and end time in a timezone, it always considers UTC. even when using TimeZone when defining a GlideSchedule. Adding the script below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 09:42 PM
check this link and it talks about using PlannedTaskAPI to calculate the duration
Calculate the business duration using a schedule
I ran the same script and in preferences set the timezone as GMT and it gave me the correct output
Note: Remember the timezone it takes is based on your user preference
try {
var schedule = new GlideSchedule("08fcd0830a0a0b2600079f56b1adb9ae", );
var open = new GlideDateTime('2025-01-03 07:00:00');
var closed = new GlideDateTime('2025-01-03 09:19:00');
// Use closed_at for "mark_closed" business rule and resolved_at for "mark_resolved" business rule
var plannedTaskAPI = new SNC.PlannedTaskAPI();
var resp = plannedTaskAPI.calculateDuration(open.getDisplayValue(), closed.getDisplayValue(), '08fcd0830a0a0b2600079f56b1adb9ae');
var response = new JSON().decode(resp);
var duration = response.duration;
gs.info(duration);
} catch (ex) {
gs.info(ex);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2025 11:46 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 09:44 PM
try this
var sched = new GlideSchedule('qwdfghjuhytfgdsew3245etrygh', 'Europe/Berlin');
var start = "2025-02-18 13:30:00"
var end = "2025-02-18 19:30:00"
var startTime = new GlideDateTime(start);
var endTime = new GlideDateTime(end);
gs.info(sched.duration(startTime, endTime));
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader