How to delete multiple Google Calendar events


IF like me you have moved from one service to another over the years, you have probably exported a calendar or two and imported it, right?

We’ll I did just that, but one of my events was a reoccurring event, so when it was imported it was added as 10,000 single events #fail

selection_053

 

I couldn’t find a good way to delete these events, so i had to rely on Google API to get this fixed.

Go to https://www.google.com/script/start/

Click on Get Started then paste in the code below and click run

You will have 10,000 events you can remove in one day.

selection_055

Below is the code used

Remember to uncomment the //var.deleteEvent() otherwise it won’t actually delete, this is here to stop people deleting by accident.

Make sure you enter your google calendar email as your var CalendarName

and var toRemove = ‘ the name of the event ‘

 

function delete_events()
{
  //take care: Date function starts at 0 for the month (January=0)
  var fromDate = new Date(2014,7,1,0,0,0); //This is August 1, 2014
  var toDate = new Date(2099,2,1,0,0,0);   //This is March 1, 2099 at 00h00'00"
  var calendarName = '[email protected]';
  var toRemove = 'Event Name here';

  var calendar = CalendarApp.getCalendarsByName(calendarName)[0];
  var events = calendar.getEvents(fromDate, toDate,{search: toRemove});
  for(var i=0; i<events.length;i++)
  {
    var ev = events[i];
    if(ev.getTitle()==toRemove) //check if the title matches
    {
      Logger.log('Item '+ev.getTitle()+' found on '+ev.getStartTime()); // show event name and date in log
      ev.deleteEvent(); //uncomment this line to actually do the delete !
    }
  }
}

 

 

Good luck and hope this helps.