I am working with a script (not mine) that takes two dates (start, end) in M/D/Y HH:MM:SS format and creates an event in Google calendar.
Now, I'm trying to change the form to have one date (start) and an option for hour duration (end). I want the duration to be added to the start date and then have the even created.
I have the script partially working where instead of the duration to show up as hours, it shows up as minutes.
I've tried multiplying endDt by 60 ( startDt + (endDt * 60) ) and a few other things, but nothing has worked so far.
I think this is the relevant portion of the code. The last line is mine.
var startDt = sheet.getRange(lr,startDtId,1,1).getValue();
var endDt = sheet.getRange(lr,endDtId,1,1).getValue();
var endDt = startDt + endDt;
Any help would be appreciated. This is the entire code if it is needed:
var calendarId = "CALENDAR_ID";
var startDtId = 4;
var endDtId = 5;
var titleId = 2;
var titleId2 = 3;
var descId = 6;
var formTimeStampId = 1;
function getLatestAndSubmitToCalendar() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var lr = rows.getLastRow();
var startDt = sheet.getRange(lr,startDtId,1,1).getValue();
var endDt = sheet.getRange(lr,endDtId,1,1).getValue();
var endDt = startDt + endDt;
var subOn = "Added :"+sheet.getRange(lr,formTimeStampId,1,1).getValue()+" by: "+sheet.getRange(lr,titleId,1,1).getValue();
var desc = "Comments :"+sheet.getRange(lr,descId,1,1).getValue()+"\n"+subOn;
var title = sheet.getRange(lr,titleId,1,1).getValue()+" - "+sheet.getRange(lr,titleId2,1,1).getValue();
createEvent(calendarId,title,startDt,endDt,desc);
};
function createEvent(calendarId,title,startDt,endDt,desc) {
var cal = CalendarApp.getCalendarById(calendarId);
var start = new Date(startDt);
var end = new Date(endDt);
var loc = 'LOCATION';
var event = cal.createEvent(title, start, end, {
description : desc,
location : loc
});
};
