Populating Date field with GMT Timestamp

mauricio23
Mega Expert

Greetings!

I have a field in the incident table, opened_at. I would like this field to be populated with the current GMT date and time instead of the user's local time preferences.

I created a dictionary over-ride using this javascript snippet:

===> javascript:gs.nowNoTZ()

However, when I go to create a new incident record, this field is not populating correctly. I would expect it to by matching the "sys_created_on".

My local time: 2016-06-21 14:22 PDT

ServiceNow values:

<opened_at>2016-06-22 04:22:10</opened_at>

<sys_created_on>2016-06-21 21:22:34</sys_created_on>

How can I get the "opened_at" timestamp to populate as the GMT ?

Screen Shot 2016-06-21 at 2.24.15 PM.png

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

The issue here is more about the display of the date and not the format of the date in the database.   All dates are stored in UTC in the DB and then translated to the user's timezone on display.



So as far as default value, I would stick with gs.nowDateTime() instead of gs.nowNoTZ(), because when the record is inserted, it will take the calculated date in the default value formula and convert it to UTC, so if you use gs.nowNoTZ(), it will sort of double -convert it to UTC.



I am not sure if there is an OOTB way to display a single date field in UTC only.   Checking the wiki now...



Jon


View solution in original post

2 REPLIES 2

Jon Barnes
Kilo Sage

The issue here is more about the display of the date and not the format of the date in the database.   All dates are stored in UTC in the DB and then translated to the user's timezone on display.



So as far as default value, I would stick with gs.nowDateTime() instead of gs.nowNoTZ(), because when the record is inserted, it will take the calculated date in the default value formula and convert it to UTC, so if you use gs.nowNoTZ(), it will sort of double -convert it to UTC.



I am not sure if there is an OOTB way to display a single date field in UTC only.   Checking the wiki now...



Jon


Thanks - I checked it out and your explanation makes perfect sense. There's no need for it to display UTC only at all times. As long as it's store in the database as UTC, I can fetch that value.



Cheers!