Skip to content

Instantly share code, notes, and snippets.

@ILAsoft
Created April 20, 2019 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ILAsoft/d380c20cc74de082c7e98c5803ac5a1c to your computer and use it in GitHub Desktop.
Save ILAsoft/d380c20cc74de082c7e98c5803ac5a1c to your computer and use it in GitHub Desktop.
Iterates through all Google Calendar events for the main calendar and deletes them (moves to trash)
function doGet() { /* Get your default calendar */
var cal = CalendarApp.getDefaultCalendar();
var yest = new Date().getTime() - 604800000; //milliseconds in a day -- go back one week
var start = new Date(0);
var end = new Date(yest);
/* Get all events from start date upto time */
var events = cal.getEvents(start, end);
var body = "Calendar - Events Log - Status" + "\n\n-----------------------\n";
body += cal.getName() + "\n\n";
if (events.length > 0) {
var tz = Session.getScriptTimeZone();
/* Build-up log */
for (var i = 0; i < events.length; i++) {
body += Utilities.formatDate(events[i].getStartTime(), tz, "MM:dd:YYYY HH:mm") + " ~ ";
body += Utilities.formatDate(events[i].getEndTime(), tz, "MM:dd:YYYY HH:mm") + " :";
body += events[i].getTitle();
events[i].deleteEvent();
body += " - Deleted!\n";
Utilities.sleep(100);
}
}
Logger.log(body);
}
function myFunction() {
doGet();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment