Why do ServiceNow time fields add an hour?

bcronrath
Kilo Guru

Why aren't ServiceNow time fields accurate?   They seem to attempt to keep in line with timezone settings, but add an hour.   For instance, let's say I create a time field, and it's set to 00:00:00 on the form with my current timezone setting of America/LA.   I then update my timezone to Australia/Sydney, and I can see the time field update to 18:00:00 on the form.   That's fine, and leads me to believe the times are stored as a proper UTC value.   However, when I try to work these values into scripts, it is adding an hour to the value.

For instance, let's say I set it back to my local time of America/LA, and now update the field to be the current time of 11:00:00.   If I do a gs.print(time field) to get the UTC printout, it comes back as 19:00:00, when in reality it should be 18:00:00 since we are in pdt currently which should equate to 7 hours off from GMT.   Even if I do a gs.nowNoTZ I get the proper value of 18:00:00, so why are the time values not being stored properly on the back end?   If I now have to program in an extra hour offset to all my calculations, is it going to be wrong when daylight saving times rolls around and we are back to pst?   This is making it unclear how to do time based calculations with scripting.

Best regards,

Brian

1 ACCEPTED SOLUTION

mloranc
Mega Expert

Hi Brian,


The problem actually lies with Daylight Savings Time. Standard timezone is -08:00, while we're in DST mode then it's -07:00. The key here is don't program an extra hour offset in your calculations when setting fields because it will mess up all your activity times after we "fall back" in November. I've done some work with time-stamps in ServiceNow and found that most of the calculation happens at render when it comes to the personal settings. The data itself is always stored in UTC.   So, using a script to display the values might give you seemingly "off" results. Just make sure those don't come through on the page load of where your data is stored and there shouldn't be a problem. I hope that kind of sheds some light. If not, feel free to ask more.


View solution in original post

6 REPLIES 6

Which version of ServiceNow are you working in? I tried your above script in Helsinki and it printed the same value for both, and it being a fix script, it didn't take any timezone modification into consideration, which is what I expected.


Ah interesting, well I'm on patch 1 of Helsinki currently.   Upgrading to the latest patch tomorrow so perhaps that might fix things.   If not I'm kind of stumped, at least that's good to know it's supposed to work though and something is just malfunctioning with my instance hehe