Data and Time Values not getting Exactly

Lucky1
Tera Guru

Hello all,

 

I am getting a change request's "Planned Start date" and "Planned End Date" values in a scripts background.

But I see there is a difference in the time shown for the data of those fields on the form and to my scripts background.

 

On the change request form:

Planned Start date: 03-11-2024 05:30:00

Planned End date: 03-11-2024 09:30:00

 

But in the scripts background it has given as:

Start date is: 2024-11-03 00:00:00

End date is: 2024-11-03 04:00:00

 

 

So, what should I do to get the exact date and time format and also exact values as shown on the form?

Please help.

 

 

Regards,

Lucky

1 ACCEPTED SOLUTION

Robert H
Mega Sage

Hello @Lucky1 ,

 

ServiceNow uses UTC as the time zone, and the YYYY-MM-DD format when storing dates on records. 

That's what you get in your script when you access the raw values.

What you see in the UI is based on your own time zone and the date/time format you selected in your preferences.

If you want your script to print the date in the same time zone and format you can do that using "getDisplayValue":

 

gs.info('raw value: ' + gr.start_date);
gs.info('display value: ' + gr.getDisplayValue('start_date'));

 

Output:

 

raw value: 2025-05-24 12:30:00
display value: 24/05/2025 05:30:00

 

Regards,

Robert

View solution in original post

6 REPLIES 6

Hello Siva,

 

Thank you very much for your response.

It's working.

But as Robert has given the first correct response, I am marking his reply as Solution.

Please never mind.

 

 

Regards,

Lucky

edwinr
Tera Contributor

Thank you this is what I ws looking for