- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 02:39 AM - edited 12-02-2024 02:48 AM
I've a job that runs every 30 minutes. On each run, the first step I need to check is if the time that the job ran lies between 11pm to 4am.
In other words, I wish to have the job run everyday during off peak hours (11pm to 4am).
Is there an elegant way to make this validation?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 02:56 AM - edited 12-02-2024 02:59 AM
Here is your elegant way to do it 🙂
var glideDateTime = new GlideDateTime();
var currentHour = glideDateTime.getHourOfDayLocalTime(); // based on 24h
if (currentHour >= 4 && currentHour < 23) {
return false; // do not execute Scheduled Job
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 02:56 AM - edited 12-02-2024 02:59 AM
Here is your elegant way to do it 🙂
var glideDateTime = new GlideDateTime();
var currentHour = glideDateTime.getHourOfDayLocalTime(); // based on 24h
if (currentHour >= 4 && currentHour < 23) {
return false; // do not execute Scheduled Job
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2024 03:09 AM
I had gone with this approach but since you answered it, will accept your solution.
var gt = new GlideTime();
var currentHour = gt.getHourOfDayLocalTime();
if([23,0,1,2,3].indexOf(currentHour) == -1){
// outside of the required slot, so do nothing
throw {message: 'Current hour is outside preferred slot' };
}
Btw, would there be any difference if I use GlideTime vs GlideDateTime as you've done it your example?