The CreatorCon Call for Content is officially open! Get started here.

Get UTC date and time, day and hours

vspk
Giga Expert

Hi All,

As part of date and time values to show to user, I need below details in Servicenow:

current utc date and time

current utc day (i.e., monday-sunday)

current utc hour(00 to 23)

 

Any way to have these 3 values in ServiceNow server side scripting?

 

Regards,

Venkata

2 REPLIES 2

Pratiksha Kalam
Kilo Sage

Hello,

Check below thread,

https://community.servicenow.com/community?id=community_question&sys_id=dde243a1dbd8dbc01dcaf3231f96...

 

If answer is helpful mark correct!

Thanks,

Pratiksha

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use getValue() on GlideDateTime() to get value in UTC

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/c_GlideDateTimeAPI#r_G...

sample script below for getting UTC values

var gdt = new GlideDateTime();

var time = new GlideTime();

gs.info('UTC time is: ' + gdt);

gs.info('UTC day of week is: ' + gdt.getDayOfWeekUTC());

gs.info('UTC Hours : ' + time.getHourOfDayUTC());

Output:

day of week - 2 meaning it is Tuesday

Week starts with Monday for UTC

find_real_file.png

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader