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 12:10 PM
Hi @rad2
Could you please try like this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 12:15 PM
Hi @rad2
Could you please try like this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 08:20 PM
I get this error when i try it
Script execution error: Script Identifier: null.null.script, Error Description: Can't find method com.glide.glideobject.GlideDateTime.setTZ(string). (null.null.script; line 19), Script ES Level: 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 08:58 PM
Convert Your Start & End Time to UTC Before Calculation
Since GlideSchedule works in UTC, manually convert your times to UTC before passing them to duration().
var sched = new GlideSchedule('qwdfghjuhytfgdsew3245etrygh'); // Replace with your schedule sys_id
var timeZone = 'Europe/Berlin';
// Convert input times to UTC
var start = new GlideDateTime("2025-02-18 13:30:00");
start.setTZ(timeZone);
gs.info("Start UTC: " + start.getValue());
var end = new GlideDateTime("2025-02-18 19:30:00");
end.setTZ(timeZone);
gs.info("End UTC: " + end.getValue());
// Calculate duration using the correct UTC times
var duration = sched.duration(start, end);
gs.info("Duration: " + duration);
Please mark helpful/correct if this helps you!