GlideDateTime: date maths you can trust
Add and subtract days, compare dates and measure durations with GlideDateTime, avoiding the time-zone mistakes that break date logic.
October 1, 2026 · #glidedatetime #dates #scripting
Date bugs usually come from mixing local time and UTC. GlideDateTime stores values in UTC; be explicit about which one you’re working with.
var now = new GlideDateTime(); // current date/time (stored in UTC)
// Add or subtract days
var due = new GlideDateTime(now);
due.addDaysUTC(5);
var weekAgo = new GlideDateTime(now);
weekAgo.addDaysUTC(-7);
// Compare: -1 (before), 0 (equal), 1 (after)
var isOverdue = now.compareTo(due) > 0;
// Duration between two dates
var created = new GlideDateTime('2026-09-01 08:00:00');
var age = GlideDateTime.subtract(created, now); // GlideDuration
gs.info('Age: ' + age.getDisplayValue()); // e.g. "30 Days 4 Hours"
gs.info('Age in days: ' + Math.floor(age.getNumericValue() / 86400000));
// Show a date in the user's time zone
gs.info('Due (user TZ): ' + due.getDisplayValue());
How it works
addDaysUTC()moves the stored UTC value;getDisplayValue()converts to the current user’s time zone for display.GlideDateTime.subtract()returns aGlideDuration;getNumericValue()gives milliseconds.
Gotchas
- String constructors expect
yyyy-MM-dd HH:mm:ssin UTC. - For business hours (excluding weekends and holidays), use a schedule with
GlideScheduleinstead of plain day maths.
MIT licence. Provided as-is, without warranty. Test in a sub-production instance first.