Insert UTC Time into A Date/Time Field Using GlideRecord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 12:45 AM
Hi Guys,
We are trying to use gliderecord to create a new record in a table.
When writing the date/time, we noticed that it's written in as the display time (local time) not the actual time (UTC).
Example like below:
---
var gr = new GlideRecord('u_table');
gr.initialize();
gr.start_date = "03/06/2017 22:10:40"
gr.insert();
---
The script above will write into the start date field with the display value of 03/06/2017 22:10:40.
However, is there a way to insert the UTC time instead?
Thanks!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 12:48 AM
Hi Kiki,
ServiceNow stores the date/time field value in UTC only.
Also is the field "start_date" in "u_table" table a date/time field?
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 04:44 AM
Hi Ankur,
Yes I know it stores UTC as the actual value but it display differently in the instance according to the user's local time.
My problem was the time I inserted into the field would become "local time" instead of UTC time and I am hoping to be able to enter UTC time.
So if I put gr.start_date = A, A shows up in our instance as the local time.
What I would like to do is gr.start_date = A and it shows up as B (local time) and A is the actual system time.
The start_date field is a date/time field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 11:30 AM
Doesn't answer op's question. I'll post a separate answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 11:29 AM
Understanding that ServiceNow Date/Time columns are always stored as UTC, I did an experiment where I tried assigning a value to a Date/Time column two different ways: