Home > Software engineering >  How to create a trigger with time range and week daysin Google ScriptApp
How to create a trigger with time range and week daysin Google ScriptApp

Time:11-25

I would like to create a trigger in Google ScriptApp, where it triggers from Monday to Friday between 9AM to 5PM, is it possible?

CodePudding user response:

I'm not sure it's possible without manually creating a trigger for every hour of the day you want the function to run.

Why not use an hourly trigger, but automatically exit the triggered function if the current time is not a week day between 9 and 5pm?

function triggeredFunction() {
  const currentDate= new Date();
if(currentDate.getDay() < 1 ||  currentDate.getDay() > 5 || currentDate.getHours() < 9 || currentDate.getHours() > 17) 
return;


// your code
}
  • Related