Create a Daily Time-Driven Trigger

Time-driven triggers are how most overnight syncs stay hands-off. This helper creates a once-per-day trigger for a named function around the hour you pick (project timezone).

What you'll need

  • A top-level function name as a string (the handler must exist in the project)
  • Rough hour of day (023) in the script's timezone

How to use this snippet

function createDailyTrigger(handlerName, hour) { hour = (hour == null) ? 6 : hour; ScriptApp.newTrigger(handlerName) .timeBased() .everyDays(1) .atHour(hour) .create(); } function installTriggers() { // Avoid duplicates — delete existing handlers first (see deleteTriggersByHandler) createDailyTrigger('runNightlySync', 2); } function runNightlySync() { // your sync logic }

Tips:

  • Calling this repeatedly stacks triggers — pair with deleteTriggersByHandler before install.
  • atHour is approximate; Apps Script runs in a window around that hour.

Happy Coding!

NitroGAS Chrome Extension

Want this snippet handy inside the Apps Script editor? NitroGAS gives you free themes and snippets — plus optional Co-Pilot when you want a boost (1-week, 1-month, or yearly passes — no subscription). Happy Coding!

Get the Extension