user13708028
user13708028

Reputation: 329

Google calendar event creation with specific hours for start and end

Based on Google script running from a Google Sheet, I'm able to create an all-day event but have some challenges with setting an event for 1 hour. I'm sure it's a very silly question but perhaps someone can tell me where to add the reference to the start and end time/hour (not date)?

Here's my code:

var eventdate = '05/08/2020';
var eventstarttime = '10:00:00';
var eventaddress = 'test location';
 var endtime = eventtime + 3600000; // one hour duration
 var timeZone = SpreadsheetApp.getActive().getSpreadsheetTimeZone();
  var calendarid = '[email protected]';
  var eventdetails = 'test details';
  
  var event = {
       location: eventaddress,
       summary: (var1 + ' related to ' + var2), // summary is built for two variables
    start: {
      date: Utilities.formatDate(eventdate, timeZone, 'yyyy-MM-dd');
   
    },
    end: {
      date: Utilities.formatDate(eventdate, timeZone, 'yyyy-MM-dd')
      },
        description: HTMLbody.getContent() // I'm using an HTML template to build a customs description based on other variables from the Sheet
  };
  event = Calendar.Events.insert(event, calendarid);

Upvotes: 0

Views: 732

Answers (1)

Cooper
Cooper

Reputation: 64082

Converting Date and Hour to DateTime:

let d='DD/MM/YYYY'.split('/');
let t='HH:MM:SS'.split(':');
let dt=new Date(d[2],d[1]-1,d[0],t[0],t[1],t[2]);

Upvotes: 1

Related Questions