- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2018 05:30 AM
Hi Guys,
I have a GlideRecord script similar to below:
=====
var gr = new GlideRecord('incident');
gr.addQuery('sys_created_on', '>', Date)
.....
=====
The Date variable will come from an api call as a parameter sent by the client. Basically they want to know how many records were created at a certain range of dates. But they will send the date/time in their local time. How do I convert their local time to ServiceNow's system time (UTC) so I can put that date into the addQuery?
Many thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2018 06:55 AM
There are a couple things to remember when doing date/time operations.
- The system stores all date/time fields as UTC - or at least it believes it does.
- If you want to apply your local to the value retrieved from a field, use getDisplayValue().
- If you want UTC, use getValue()
- 2 and 3 also apply to setDisplayValue() and setValue().
Once you keep it straight in your head when a TZ is applied (e.g. display values) and when it is not (getValue()/setValue()) everything else becomes pretty easy.
Based your requirement, you want to take the value the user gave you, and strip the timezone - something like this:
// change user.date to whatever variable the user gave you
var gr = new GlideRecord('incident');
var date = new GlideDateTime();
date.setDisplayValue(user.date); // insert it in to the variable with TZ applied, so the internal value has no TZ
gr.addQuery('sys_created_on', '>', date);
Standard disclaimer: The following code is untested, requires review and potential modifications.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2018 05:32 AM
Thanks Chuck! That solved my problem!