title: How to create Google Calendar All Day Events from spreadsheet that is update-able without creating duplicates
body: <p>I have been using the Google Apps Script with code from this <a href="https://stackoverflow.com/questions/15788897/create-google-calendar-events-from-spreadsheet-but-prevent-duplicates">question</a> to create update-able (from spreadsheet) calendar events, without creating duplicates.</p>
  
  <pre><code>/**
   * Adds a custom menu to the active spreadsheet, containing a single menu item
   * for invoking the exportEvents() function.
   * The onOpen() function, when defined, is automatically invoked whenever the
   * spreadsheet is opened.
   * For more information on using the Spreadsheet API, see
   * https://developers.google.com/apps-script/service_spreadsheet
   */
  function onOpen() {
    var sheet = SpreadsheetApp.getActiveSpreadsheet();
    var entries = [{
      name : "Export Events",
      functionName : "exportEvents"
    }];
    sheet.addMenu("Calendar Actions", entries);
  };
  
  /**
   * Export events from spreadsheet to calendar
   */
  function exportEvents() {
    var sheet = SpreadsheetApp.getActiveSheet();
    var headerRows = 1;  // Number of rows of header info (to skip)
    var range = sheet.getDataRange();
    var data = range.getValues();
    var calId = "YOUR_CALENDAR_ID";
    var cal = CalendarApp.getCalendarById(calId);
    for (i=0; i&lt;data.length; i++) {
      if (i &lt; headerRows) continue; // Skip header row(s)
      var row = data[i];
      var date = new Date(row[0]);  // First column
      var title = row[1];           // Second column
      var tstart = new Date(row[2]);
      tstart.setDate(date.getDate());
      tstart.setMonth(date.getMonth());
      tstart.setYear(date.getYear());
      var tstop = new Date(row[3]);
      tstop.setDate(date.getDate());
      tstop.setMonth(date.getMonth());
      tstop.setYear(date.getYear());
      var loc = row[4];
      var desc = row[5];
      var id = row[6];              // Sixth column == eventId
      // Check if event already exists, update it if it does
      try {
        var event = cal.getEventSeriesById(id);
      }
      catch (e) {
        // do nothing - we just want to avoid the exception when event doesn't exist
      }
      if (!event) {
        //cal.createEvent(title, new Date("March 3, 2010 08:00:00"), new Date("March 3, 2010 09:00:00"), {description:desc,location:loc});
        var newEvent = cal.createEvent(title, tstart, tstop, {description:desc,location:loc}).getId();
        row[6] = newEvent;  // Update the data array with event ID
      }
      else {
        event.setTitle(title);
        event.setDescription(desc);
        event.setLocation(loc);
        // event.setTime(tstart, tstop); // cannot setTime on eventSeries.
        // ... but we CAN set recurrence!
        var recurrence = CalendarApp.newRecurrence().addDailyRule().times(1);
        event.setRecurrence(recurrence, tstart, tstop);
      }
      debugger;
    }
    // Record all event IDs to spreadsheet
    range.setValues(data);
  }
  </code></pre>
  
  <p>I can get it to work but now I want to create an all day event rather than an event with a start and end time.</p>
  
  <p>I have found the codes for all day events <a href="https://developers.google.com/apps-script/reference/calendar/calendar.html#createAllDayEvent(String,Date,Object)" rel="nofollow noreferrer">here</a></p>
  
  <pre><code>    // Creates an all-day event for the moon landing and logs the ID.
  var event = CalendarApp.getDefaultCalendar().createAllDayEvent('Apollo 11 Landing',
      new Date('July 20, 1969'),
      {location: 'The Moon'});
  Logger.log('Event ID: ' + event.getId());
  </code></pre>
  
  <p>I dont know how to combine the two. Any Help would be much appreciated, I am a noob when it comes to coding!</p>
  
  <p>Edit: Revised code</p>
  
  <pre><code>**
   * Adds a custom menu to the active spreadsheet, containing a single menu item
   * for invoking the exportEvents() function.
   * The onOpen() function, when defined, is automatically invoked whenever the
   * spreadsheet is opened.
   * For more information on using the Spreadsheet API, see
   * https://developers.google.com/apps-script/service_spreadsheet
   */
  function onOpen() {
    var sheet = SpreadsheetApp.getActiveSpreadsheet();
    var entries = [{
      name : "Export Events",
      functionName : "exportEvents"
    }];
    sheet.addMenu("Calendar Actions", entries);
  };
  
  /**
   * Export events from spreadsheet to calendar
   */
  function exportEvents() {
    var space = " - "
    var sheet = SpreadsheetApp.getActiveSheet();
    var headerRows = 1;  // Number of rows of header info (to skip)
    var range = sheet.getDataRange();
    var data = range.getValues();
    var calId = "en0d0u4gismehh6qmkstskfavk@group.calendar.google.com";
    var cal = CalendarApp.getCalendarById(calId);
    for (i=0; i&lt;data.length; i++) {
      if (i &lt; headerRows) continue; // Skip header row(s)
      var row = data[i];
      var date = new Date(row[0]);  // First column
      var numb = row[3];
      var title = numb.substring(11,6) +space+ row[1];
      var loc = row[2];
      var id = row[4];              // Sixth column == eventId
      // Check if event already exists, update it if it does
      try {
        var event = cal.getEventSeriesById(id);
      }
      catch (e) {
        // do nothing - we just want to avoid the exception when event doesn't exist
      }
      if (!event) {
        //cal.createEvent(title, new Date("March 3, 2010 08:00:00"), new Date("March 3, 2010 09:00:00"), {description:desc,location:loc});
        var newEvent = cal.createAllDayEvent(title, date, {location:loc}).getId();
        row[4] = newEvent;  // Update the data array with event ID
      }
      else {
        event.setTitle(title);
        event.setLocation(loc);
        // event.setTime(tstart, tstop); // cannot setTime on eventSeries.
        // ... but we CAN set recurrence!
        var recurrence = CalendarApp.newRecurrence().addDailyRule().times(1);
        event.setRecurrence(recurrence, date);
      }
      debugger;
    }
    // Record all event IDs to spreadsheet
    range.setValues(data);
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/l86mA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l86mA.png" alt="spreadsheet"></a></p>