I have a google spreadsheet for payroll, with a script that needs to run every other week. Right now, I'm running it manually. I would like to use a time-driven trigger, but i can't figure out any combination that will do every other Thursday at 1am. Anyone know a way this might be done?
function createBiWeeklyTrigger() {
// Trigger every other Monday at 06:00.
ScriptApp.newTrigger('function_name')
.timeBased()
.everyWeeks(2)
.onWeekDay(ScriptApp.WeekDay.MONDAY)
.atHour(6)
.create();
}
you could prototype extend the date object to give you a week number and then choose to call only on even numbered weeks (or odd obviously)
Date.prototype.getWeekNumber = function() {
var firstDay = new Date(this.getFullYear(),0,1);
return Math.ceil((((this - firstDay) / 86400000) + firstDay.getDay()+1)/7);
}
and then in your weekly on a thursday trigger, wrap the whole lot in a conditional like
if (today.weekNumber() % 2 === 0) {
// triggered function here
}
but I think i like Phil Bozak's on/off flag approach
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With