Convert Date Time to UTC

sandeep24
Tera Guru

Hi,

ON NEW FORM when user selects DATETIME field(ex: start date), I need to convert it to UTC time in Client Script(or using GlideAjax)

 

Thanks

1 ACCEPTED SOLUTION

Hi,

Perhaps it's doing that because it's not saved to the database at that time. I see why you were specifically mentioning "new" record in your post. I didn't see that before.

With that said, you should be able to still use GlideAjax, onChange client script, for example, take that value from that field, send it to your script include and use that to "set the display value" of a GlideDateTime object, so not set the value, but set the display value of a GlideDateTime object.

Then...get the value, send it back to your client for use in your alert or whatever you need to do.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

12 REPLIES 12

Robbie
Kilo Patron
Kilo Patron

Hi Sandeep,

Can you expand on the requirement and why you need to 'convert' this to UTC? The reason I ask is because all times are stored in UTC and appear globally based on the system time zone.

Additionally you will find however that users will be presented with that time based on their local time zone, according to their user preference settings. (Eg UK - GMT or US - PST).

See - https://docs.servicenow.com/en-US/bundle/sandiego-platform-administration/page/administer/time/reference/r_TimeZones.html

To answer your question specifically (with no context),you can use getValue() on GlideDateTime() to get value in UTC as below.

To help others, please mark correct and/or helpful.

Thanks,

Robbie

https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server_legacy/c_GlideDateTimeAPI#r_GDT-getValue

Hi Robbie,

Thank you for your time,

Requirement is to alert schedule based on Start Date on NEW CHNAGE Form.

 

when I use alert(g_form.getValue('start_date')); it is displaying datetime in USER Timezone,

But i want in UTC Time Zone.

 

For OLD records, i can use GLideAjax and then user glidequery on change record and then change.getValue('start_date')

I want same functionality for NEW record also.

 

so need help to convert user time zone(ex: IST/US Pacific/Israel) to UTC in client script/ajax on NEW FORM

 

Thanks,

Allen Andreas
Administrator
Administrator

Hello,

If you "get the value" of the date/time field...it's already in UTC format (as the server value time is UTC).

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

Thank you for your time,

Requirement is to alert schedule based on Start Date on NEW CHNAGE Form.

 

when I use alert(g_form.getValue('start_date')); it is displaying datetime in USER Timezone,

But i want in UTC Time Zone.

 

For OLD records, i can use GLideAjax and then user glidequery on change record and then change.getValue('start_date')

I want same functionality for NEW record also.

 

so need help to convert user time zone(ex: IST/US Pacific/Israel) to UTC in client script/ajax on NEW FORM

 

Thanks,