How can I check that the Current Time is after a Specific Time?

simonbourne
Kilo Contributor

I need to set a flag field based on the time that an Incident is raised.

I need to compare the current time with specific time, depending on the client.  For example, if the Created time is after 18:00 set the flag to TRUE.  What would be the syntax for the checking the time?

2 REPLIES 2

him001
ServiceNow Employee
ServiceNow Employee

Hi,

You can use below script to get current time.

var gdt = new GlideDateTime(); // current time in GMT
var userDateTimeZone = gdt.getDisplayValue(); // in local time
var userTime = userDateTimeZone.split(' ')[1]; // parsed time field
gs.print(userTime); // return in HH:MM:SS format

 

Since userTime is in the format HH:MM:SS, we can compare it with specific time as per normal string comparison.

if (userTime > Specific time) {
// Incident condition to set flag true
}

Provided both are in HH:MM:SS format (userTime is already in this format).

 

Hope this helps.

 

Thanks,

Himanshu

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


This will solve your issue:

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

 

Thanks,
Ashutosh