ServiceNow's GlideDateTime handles server-side date operations but has a critical duality that trips up developers: getValue() returns the UTC database string, while getDisplayValue() returns a timezone-adjusted, locale-formatted string. Most bugs stem from using the wrong method for your context — storing display values in the database corrupts queries, while showing UTC strings confuses users.

When to use this

  • Setting datetime fields in Business Rules or Script Includes
  • Timestamping records for audit trails or SLA calculations
  • Creating date ranges for GlideRecord queries with specific time boundaries
  • Scheduled Jobs that need to track execution time or process time-sensitive data

When NOT to use this

  • Client-side scripts — use new Date() or call server via GlideAjax
  • Simple current timestamp logging — use gs.now() for date-only or gs.nowNoTZ() for simple strings
  • Performance-critical loops — instantiating GlideDateTime repeatedly is expensive
  • Scoped applications without sufficient privileges — may fail silently

Key behaviors and gotchas

  • getValue() returns UTC in format yyyy-MM-dd HH:mm:ss — this is what gets stored in datetime database fields
  • getDisplayValue() adjusts for current user's timezone and date/time format preferences
  • gs.nowDateTime() is identical to new GlideDateTime() — use whichever is more readable
  • getMonth() returns 1-12, not 0-11 like JavaScript's Date object
  • Always compare dates using getValue() strings — display values vary by user and break comparisons
  • addDaysUTC() and addDays() behave differently across daylight saving time boundaries
⚠️

Never store getDisplayValue() results in datetime fields — they become unsortable strings that break queries. Always store getValue() for database fields, only use getDisplayValue() for user-facing messages.

Free Newsletter

Enjoying this? Get one deep-dive per week.

Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.

No spam · Unsubscribe anytime