How to get Current hour in Scheduled job script?

Akki1
Tera Contributor

Hi,

I'm trying to get the current hour and minute in Scheduled job script but I don't know how to get it . Can someone help here?

5 REPLIES 5

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hi @Akki1 

Greetings!

I don't think we have glidedate API for hours and minutes. 

refer below thread if it might be helpful.

https://www.servicenow.com/community/developer-forum/glidedatetime-get-hours-minutes-and-seconds/m-p...

https://www.servicenow.com/community/developer-forum/glidedatetime-get-hours-minutes-and-seconds/m-p...

Please mark my answer as helpful and correct if helped.

 

Kind Regards,

Ravi Chandra

Sonu Parab
Mega Sage

Hello @Akki1 

you can use the GlideDateTime API to get the current hour and minute in a Scheduled Job script. Here's an example of how you can achieve this:

 

// Get the current date and time
var currentTime = new GlideDateTime();

// Get the current hour and minute
var currentHour = currentTime.getHourOfDayUTC();
var currentMinute = currentTime.getHourOfMinuteUTC();

// Log the values
gs.info("Current Hour: " + currentHour);
gs.info("Current Minute: " + currentMinute);

 

If my response successfully addresses your query, I kindly request you to consider marking it as the accepted solution. Doing so can be beneficial for others who might have a similar concern.

Thank you!

Akki1
Tera Contributor

@Sonu Parab This is a ChatGPT reply 🙂
We don't have getHourOfDay() and getMinute() methods