2

To delete multiple events, I used the script in this answer - How to delete all events on many dates all at once but not the whole Calendar in Google Calendar?

var fromDate = new Date(2013,0,1,0,0,0);
var toDate = new Date(2013,0,4,0,0,0);
var calendarName = 'My Calendar';

// delete from Jan 1 to end of Jan 4, 2013

var calendar = CalendarApp.getCalendarsByName(calendarName)[0];
var events = calendar.getEvents(fromDate, toDate);
for(var i=0; i<events.length;i++){
  var ev = events[i];
  Logger.log(ev.getTitle()); // show event name in log
  ev.deleteEvent();
}

However, the problem I have is that I have around 50 events per month which are recurring every year (birthdays), so it just goes on and on. How can I delete to make sure the recurring events are deleted as well?

1

You want to delete not just the particular Event but the Event Series to which it belongs. So, instead of ev.deleteEvent(); use

ev.getEventSeries().deleteEventSeries();

This should also work for events that aren't repeated, because the method getEventSeries wraps them in a new EventSeries object.

0

This will help:

function delete_rec_events()
{
  //take care: Date function starts at 0 for the month (January=0)
  var fromDate = new Date(2018,0,1,0,0,0); //This is January 1, 2018
  var toDate = new Date(2018,0,10,0,0,0);   //This is January 10, 2018 at 00h00'00"

  var calendarName = '<Name of the Calendar>';
  var calendar = CalendarApp.getCalendarsByName(calendarName)[0];
  var events = calendar.getEvents(fromDate, toDate);

  for (var i=0; i<events.length;i++)
  {
    var ev = events[i];
    Logger.log('Checking Event Title === ' + calendar.getEventSeriesById(ev.getId()).getTitle());
    calendar.getEventSeriesById(ev.getId()).deleteEventSeries();
    Logger.log('Event Deleted'); 
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.