ServiceNow Date & Time Helper

Live

See any date the way GlideDateTime does, in any time zone, and get tested code to add time, compare, measure working hours and filter by date.

1 The date

Value
The value is

2 What do you want to do?

Convert
Calculate
Business time
Records and queries
Client side

3 Every value ServiceNow gives

In the code, the date comes from
Application
MethodReturns
getValue()Stored value, UTC2026-10-21 08:30:00
getDisplayValue()Europe/Stockholm, yyyy-MM-dd HH:mm:ss2026-10-21 10:30:00
getDisplayValueInternal()Europe/Stockholm, yyyy-MM-dd HH:mm:ss2026-10-21 10:30:00
getNumericValue()Milliseconds since 1970 UTC1792571400000
getLocalDate().getValue()The user’s date2026-10-21
getDate().getValue()The UTC date2026-10-21
getDayOfWeekLocalTime()Wednesday, 1 = Monday3
getTZOffset()UTC+02:00 on this date, in ms7200000
ISO 8601For integrations2026-10-21T08:30:00Z

Server script

Script Checker: no problems
Global
var gdt = new GlideDateTime('2026-10-21 08:30:00');  // 2026-10-21 10:30:00 for a user in Europe/Stockholm
gs.info(gdt.getValue());                 // 2026-10-21 08:30:00  stored, UTC
gs.info(gdt.getDisplayValue());          // 2026-10-21 10:30:00  the user's time zone and date format
gs.info(gdt.getDisplayValueInternal());  // 2026-10-21 10:30:00  the user's time zone, yyyy-MM-dd HH:mm:ss
gs.info(gdt.getNumericValue());          // 1792571400000  milliseconds since 1970-01-01 UTC
gs.info(gdt.getLocalDate().getValue());  // 2026-10-21  the user's date
gs.info(gdt.getDate().getValue());       // 2026-10-21  the UTC date
gs.info(gdt.getDayOfWeekLocalTime());    // 3  Wednesday (1 = Monday, 7 = Sunday)
  • “The user” is whoever the code runs as. Scheduled jobs and events usually run as system, in the instance’s default time zone, not the time zone of the person the date is for.

One moment, three ways to write it

Stored valuegetValue(), setValue(), new GlideDateTime(text)
UTC, always yyyy-MM-dd HH:mm:ss. What the database holds and what you should calculate with.
Display valuegetDisplayValue(), setDisplayValue()
The user’s time zone and their own date format. For showing to people, never for maths.
Internal display valuegetDisplayValueInternal(), setDisplayValueInternal()
The user’s time zone in yyyy-MM-dd HH:mm:ss. Useful to set the user’s midnight or end of day.

Mistakes that shift dates

Writing getDisplayValue() into a field
The time shifts by the user’s offset. Write getValue().
x = gdt.addDaysLocalTime(3)
The add methods return nothing; they change gdt itself.
Comparing date strings
"10/21/2026" sorts before "9/30/2026" as text. Compare GlideDateTime objects.
Parsing without a format
setDisplayValue() reads the format of whoever runs the code. Pass the format.
Weekdays as working days
Holidays are still counted. Use a schedule.
Forgetting who the user is
Scheduled jobs run as system, in the instance’s time zone, not the requester’s.

Not allowed in scoped apps, and what to use instead

These GlideDateTime and GlideSystem calls work in the global scope only. The helper writes the scoped version when you choose “A scoped app”.

Global onlyWorks in every scope
addDays(n)addDaysLocalTime(n) or addDaysUTC(n)
gs.dateDiff(a, b)end.getNumericValue() - start.getNumericValue(), or GlideDateTime.subtract(start, end)
gs.nowDateTime()new GlideDateTime()
setTimeZone(tz)A global script include, called from the scoped app
setNumericValue(ms)new GlideDateTime('1970-01-01 00:00:00') then add(ms)

Local time or UTC?

On most days they agree. When a daylight saving change falls between the two dates, addDaysLocalTime(1) keeps the clock time (10:30 stays 10:30) while addDaysUTC(1) adds exactly 24 hours (10:30 becomes 09:30 or 11:30). For due dates people read, local time is usually what they expect. Enter 2026-10-24 08:30:00 above with Europe/Stockholm and add one day to see it.

Date pattern letters

ServiceNow formats and parses dates with Java SimpleDateFormat patterns, in setDisplayValue(value, format), getByFormat() and the date format on the user record.

yyyy2026
yy26
MM10
MMMOct
MMMMOctober
dd21
EEEWed
EEEEWednesday
HH00-23
hh01-12
mmminutes
ssseconds
aAM / PM
'at'literal text

Frequently asked questions

How do I add days to a date in ServiceNow?

Create a GlideDateTime and call addDaysLocalTime(n) or addDaysUTC(n); use a negative number to subtract. The methods change the object and return nothing. addDays() is not allowed in scoped apps. LocalTime keeps the clock time the user sees when a daylight saving change falls in between; UTC adds whole 24-hour days. The helper shows both results side by side.

What is the difference between getValue() and getDisplayValue() on a GlideDateTime?

getValue() returns the stored value in UTC as yyyy-MM-dd HH:mm:ss. getDisplayValue() returns the same moment in the time zone and date format of the user the code runs as. Calculate and store with getValue(); show getDisplayValue() to people.

Why is my date off by a few hours?

Almost always a display value used as a stored value, or the other way round: for example setValue() with a time the user typed, or getDisplayValue() written into a field. Enter the date above as one form and read the others to see where the hours went.

How do I calculate the difference between two dates in ServiceNow?

Subtract the numeric values: end.getNumericValue() - start.getNumericValue() gives milliseconds, which works in every scope. GlideDateTime.subtract(start, end) gives a GlideDuration whose getDisplayValue() reads like "2 Days 3 Hours". gs.dateDiff() is global only.

How do I count only business days or business hours?

Use a schedule. Load it with new GlideSchedule(sys_id), then schedule.add(start, duration) gives a due date that skips nights, weekends and holidays, and schedule.duration(start, end) gives the working time between two dates. The helper finds the schedule by name so the code does not hard-code a sys_id.

How do I get the start of today, the week or the month in the user’s time zone?

Take the user’s date with getLocalDate() and set the time with setDisplayValueInternal(date + ' 00:00:00'). For weeks, move to Monday with addDaysLocalTime(1 - getDayOfWeekLocalTime()) first. In an encoded query, javascript:gs.beginningOfToday() and its siblings do the same.

How do I filter records created in the last 7 days?

Use the encoded query sys_created_onRELATIVEGE@dayofweek@ago@7 with addEncodedQuery(). ServiceNow calls the day unit dayofweek. For calendar ranges such as this month, the ON operator with gs.beginningOfThisMonth() and gs.endOfThisMonth() is what the list filter builds.

Can I work with dates in a client script?

In the classic UI, getDateFromFormat(value, g_user_date_time_format) turns a field value into milliseconds and formatDate(date, g_user_date_time_format) turns a Date back into the user’s format. Neither exists in the Service Portal or mobile; there, do the work on the server with GlideAjax.