I need to create a script to run every hour only between working hours (say 9 am to 5 pm) between Monday to Friday. I scheduled the trigger to run the script every hour, however such scheduling does not allow to limit the script running within working hours of Monday to Friday, so I want to build the scheduling function within the script. I am trying below script, but that not working:
function Auto_Update() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
if {
1<Weekday(NOW())<7 {
if {
8<text(now(),"hh") <18
<<My script>>
}
}
}
};
Please assist.
Weekday() and Now() are google Sheet functions. You need JavaScript functions to manipulate dates. See here for more.
To check if the value of variable is in a range, you need to use the &&
(and) operator. Something like this:
function Auto_Update() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var today = new Date();
var dayOfWeek = today.getDay();
var hourOfDay = today.getHours();
if(dayOfWeek > 0 && dayOfWeek < 7 && hourOfDay > 8 && dayOfWeek < 18) {
//your script here
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.