Trying to write a function to export Google Calendar entries into a Google Sheet. I've created two calendar entries in the date range 2019/02/01 - 2019/03/01 with the text #outreach. The search works and finds the two events I created, and only the two events I created. However, the getStartTime, getEndTime, and getDateCreated functions all return the date/time that I run the function:
function myFunction() {
var defaultCalendar = CalendarApp.getDefaultCalendar();
var lower = new Date(2019, 2, 1);
var upper = new Date(2019, 3, 1);
var events = CalendarApp.getDefaultCalendar().getEvents(lower, upper, {search: '#outreach'});
var startTime = Date(events[1].getStartTime());
Logger.log('Start time: %s', startTime);
var endTime = Date(events[1].getEndTime());
Logger.log('End time: %s', endTime);
var createDate = Date(events[1].getDateCreated());
Logger.log('Create date: %s', createDate);
}
Any ideas as to why?
Comment by https://stackoverflow.com/users/9337071/tehhowch was the solution, i.e., I needed to add the new keyword, as follows var startTime = new Date(events[1].getStartTime()); Logger.log('Start time: %s', startTime);
Some Calendar Events to Spreadsheet
This function also launches a modeless dialog with table of the events found by the search. You'll probably need to change sheet name and search string