I am having some difficulty in creating a trigger to execute each day at specifically 6:05am. (Australia/Melbourne time).
I have made sure to set the correct time-zone in spreadsheet setting, Project settings and even physically in my code.
The logs says it has the correct time, and it has all the necessary information to create the trigger for the current day at 6:05am
Log File:
12:33:55 PM Info Thu Jan 13 00:00:00 GMT+11:00 2022
12:33:55 PM Info [2022.0, 0.0, 13.0, 6.0, 5.0]
12:33:55 PM Info Thu Jan 13 06:05:00 GMT+11:00 2022
However when I go check the triggers dashboard (in Google App Script) it keeps creating the trigger for the current time:
Example the current time now is: 2022-01-13 12:34 <-- Which is the time the trigger was created for.
My Code:
function setTrigger() {
deleteTriggers();
var today_D = Utilities.formatDate(new Date(), SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "yyyy MM dd");
var newDate = new Date(today_D)
Logger.log(newDate)
var year = newDate.getFullYear();
var month = newDate.getMonth();
var day = newDate.getDate();
pars = [year,month,day,06,05];
Logger.log(pars)
var scheduled_D = new Date(...pars);
Logger.log(scheduled_D)
ScriptApp.newTrigger("function_Triggered")
.timeBased()
.at(scheduled_D)
.create()
}
function deleteTriggers() {
var triggers = ScriptApp.getProjectTriggers();
for (var i = 0; i < triggers.length; i++) {
if ( triggers[i].getHandlerFunction() == "function_Triggered") {
ScriptApp.deleteTrigger(triggers[i]);
}
}
}
function function_Triggered() {
Gmail2GDriveVolume()
}
Any help would be greatly appreciated.