Reputation: 1
Here is my code:
function calEvent(){
var arrivalDate = "06/10/2013";
var departureDate = "06/18/2013";
var start = new Date(arrivalDate);
var end = new Date(departureDate);
var cal = CalendarApp.getCalendarById('[email protected]');
cal.createEvent('Apollo 11 Landing',start,end);
}
When I run this it will create the event in the correct calendar however it will only be from June 10 thru June 17. I need the event to cover June 10 - June 18.
I have checked the Timezone setting and the spreadsheet, script and calendar are all on the same time zone (Mountain Time GMT-7)
How can I get this seemingly simple code to set the event on the correct dates? I've tried several date formatting (utilities.formatDate) but can't seem to get the correct format.
Thanks in advance.
Upvotes: 0
Views: 3028
Reputation: 571
How to use timeZone of calendar to set timeZone for date object
I posed the above question a couple a weeks ago, and came up with a working solution. Not sure if it is the best or not, but you can look over and see if it helps. In working on a solution for my question I noticed several things. The script definitely uses the script timezone to create a date object. But when it post to a calendar it adjust the date to executors default calendar timezone not the timezone of the calendar you're writing too. So if a user's default calendar timezone is different from the calendar being written to you will get all kind of crazy time's
So the function gasTimezoneOffset() that is listed in the above question was my solution for this.
Hope this helps.
Upvotes: 1