Home > Enterprise >  Stop the Google App script trigger on specific dates
Stop the Google App script trigger on specific dates

Time:09-08

I use the following Script that is triggered on all weekdays:

function shouldRunTrigger() {
  var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
  var date = new Date();
  var day = days[date.getDay()];
  if ((day === "Sat") || (day === "Sun")) {
    return false;
  }
  return true;
}
function myTrigger() {
  if (!shouldRunTrigger()) return;
  // trigger code here
}

I would like exclude National holidays like 26th Jan, 15th Aug & 02nd Oct of each year, any help on how to acheive this?

CodePudding user response:

Add this below your 'date' var:

var fmtDate = Utilities.formatDate(date, Session.getScriptTimeZone(), 'MMM.dd')

Then add dates to your 'exclude' statement:

if ((day === "Sat") || (day === "Sun") || (fmtDate === "Jan.26") || (fmtDate === "Aug.15")) {
    return false;
  }
  return true;
}
  • Related