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

Run a schedule job at 2 am from Monday to Friday and at 8 am on Weekends.

SNewbies
Tera Contributor

Hello!

I want to run a Scheduled Job at 2 am from Monday to Friday and run same Scheduled Job at 8 am on Saturday and Sunday. How can do this?

Thank you

6 REPLIES 6

Harish KM
Kilo Patron
Kilo Patron

Hi @SNewbies since you want to run on different time you would need 2 schedule jobs

1. run on weekday

2 run on weekend

In both Scheduled Jobs please enable the Condition checkbox and paste the below code.

var answer = false;

var now = new GlideDateTime();

for weekday check

if(now.getDayOfWeekUTC() !=6 && now.getDayOfWeekUTC() !=7 )       // this scheduled job will run only on Weekdays

{

      answer = true;

}

for weekend check

if(now.getDayOfWeekUTC() ==6 && now.getDayOfWeekUTC() ==7 )       // this scheduled job will run only on weekends

{

      answer = true;

}

example:

HarishKM_0-1709269352887.png

 

Regards
Harish

AndersBGS
Tera Patron
Tera Patron

Hi @SNewbies 

 

You should be able to do something like below:

 

 

 

 

// Get the current date and time
var now = new Date();

// Get the current day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
var dayOfWeek = now.getDay();

// Get the current hour
var hour = now.getHours();

// Check if it's Monday to Friday and time is 2 am
if (dayOfWeek >= 1 && dayOfWeek <= 5 && hour === 2) {
    // Execute logic for Monday to Friday at 2 am
    gs.info('Executing script for Monday to Friday at 2 am');
    // Write your logic here
}
// Check if it's Saturday or Sunday and time is 8 am
else if ((dayOfWeek === 0 || dayOfWeek === 6) && hour === 8 {
    // Execute logic for Saturday and Sunday at 8 am
    gs.info('Executing script for Saturday and Sunday at 8 am');
    // Write your logic here
}
else {
    // For all other times, log that the script is not scheduled to run
    gs.info('Script is not scheduled to run at this time');
}

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/