In our previous article (Part 76), we took our first step into automating Google Calendar by learning how to retrieve specific calendars—such as the Sapporo Office Meeting Room 1 calendar—using CalendarApp.getCalendarById()!
Once you have prepared the target calendar in Google Apps Script (GAS), the next thing you naturally want to do is write events into your calendar automatically from code.
- “I want to bulk-register events to Google Calendar from a meeting schedule list in Google Sheets.”
- “I want to automatically schedule the recurring ‘Sapporo Office Monthly Report Meeting’.”
- “I want to automatically set all-day events like ‘Sapporo Office Foundation Day’ or company-wide training sessions.”
Opening Google Calendar manually to type in titles, dates, and times one by one gets overwhelming as the number of events grows. It also opens the door to human errors like typos and duplicate bookings.
That is why in this 77th article of our series, we will thoroughly explain the two essential methods for automatically creating Google Calendar events: Calendar.createEvent() and Calendar.createAllDayEvent()!
Using real-world scenarios from our Sapporo office (a timed “Monthly Report Meeting” and an all-day “Office Foundation Day”), we will cover everything from writing clean code and passing handy optional parameters to avoiding common beginner traps with time zones and date ranges in the clearest way possible!
1. What Are createEvent and createAllDayEvent?
When adding a new event to Google Calendar with GAS, you choose between two methods depending on whether you need a timed appointment or a full-day event.
| Method Name | Event Type | Primary Use Case | Required Arguments |
createEvent() |
Timed Event (Specific hours) | Meetings, client visits, seminars, appointments, etc. | Title, Start Time, End Time |
createAllDayEvent() |
All-Day Event (Full day) | Anniversaries, holidays, business trips, all-day training, company holidays, etc. | Title, Target Date |
Picture It as a Daily Planner!
Let’s visualize this using a physical daily planner, just like our familiar analogies throughout this series.
- Calendar Object (
Calendar) = The physical planner notebook itself createEvent()= Writing an appointment into the hourly grid (e.g., 2:00 PM – 3:30 PM) with a pencreateAllDayEvent()= Highlighting a note at the very top of the daily page in the “All-Day Notes” section
Calling either method on your retrieved Calendar object instantly generates a new event directly on Google Calendar.
2. STEP 1: Preparation! Get the Calendar to Work With
First, as a quick review of Part 76, let’s retrieve the Google Calendar where you want to add events using GAS.
In this guide, you can use your personal primary (default) calendar or a shared calendar such as “Sapporo Office Meeting Room 1”.
Basic Code (Retrieving a Calendar)
// Pattern A: Get your primary default calendar
var calendar = CalendarApp.getDefaultCalendar();
// Pattern B: Get a specific calendar by ID (Review of Part 76)
var calendar = CalendarApp.getCalendarById("sapporo-room1@example.com");
*In the following sample snippets, we will use CalendarApp.getDefaultCalendar() for quick testing, but substituting a specific calendar ID will work exactly the same way.
3. STEP 2: [Practice 1] How to Create a Timed Event with Calendar.createEvent()
Now let’s create an actual timed event: the “Sapporo Office Monthly Report Meeting”!
1. Enter the Code
Open your Google Sheets script editor or a standalone GAS editor and paste the following code:
function createMonthlyReportEvent() {
// 1. Get the primary calendar (open your planner)
var calendar = CalendarApp.getDefaultCalendar();
// 2. Prepare the start and end dates/times (Date objects)
// Example: October 15, 2026, from 14:00 to 15:30
var startTime = new Date("2026/10/15 14:00:00");
var endTime = new Date("2026/10/15 15:30:00");
// 3. Create the timed event (title, startTime, endTime)
var event = calendar.createEvent("[Sapporo Office] Monthly Report Meeting", startTime, endTime);
// 4. Output the created event title to the log to verify
Logger.log("Event created!: '" + event.getTitle() + "'");
}
2. Detailed Line-by-Line Breakdown
new Date("2026/10/15 14:00:00")- This creates a JavaScript Date object to handle specific dates and times.
- Passing a string in the format
"YYYY/MM/DD HH:mm:ss"is the most intuitive way to define an exact date and time.
calendar.createEvent(title, startTime, endTime)- Pass the event title (string) as the first argument, the start Date object as the second, and the end Date object as the third.
event.getTitle()- Upon success,
createEvent()returns aCalendarEventobject. Calling its.getTitle()method allows you to verify that the event was registered with the correct title.
- Upon success,
3. Save, Run, and Verify
- Save your script (floppy disk icon) and run
createMonthlyReportEvent. - On your first run, an authorization pop-up will appear. Follow the prompts on screen to grant calendar permissions (see Part 2 for details).
- Open Google Calendar! If “[Sapporo Office] Monthly Report Meeting” appears on October 15, 2026, from 14:00 to 15:30, your script ran successfully!
4. STEP 3: [Practice 2] How to Create an All-Day Event with Calendar.createAllDayEvent()
Next, let’s create a full-day event instead of a time-specific meeting.
Here, we will register “Sapporo Office Foundation Day” as an all-day event.
1. Enter the Code
function createAnniversaryEvent() {
// 1. Get the primary calendar
var calendar = CalendarApp.getDefaultCalendar();
// 2. Prepare the target date for the all-day event
var anniversaryDate = new Date("2026/11/01");
// 3. Create the all-day event (title, date)
var event = calendar.createAllDayEvent("Sapporo Office Foundation Day", anniversaryDate);
// 4. Output the confirmation log
Logger.log("All-day event created!: '" + event.getTitle() + "'");
}
2. Key Points Explained
calendar.createAllDayEvent(title, date)- There is no need to specify a time (like 14:00). Simply passing a date like
new Date("2026/11/01")places the event squarely in the all-day banner area at the top of that calendar day.
- There is no need to specify a time (like 14:00). Simply passing a date like
5. STEP 4: Creating Multi-Day All-Day Events
You might often want to create continuous all-day events across multiple days, such as “Sapporo Business Trip (3 days from Nov 10 to Nov 12)”.
By passing three arguments to createAllDayEvent(), you can create an all-day event spanning a date range (start date to end date)!
Code Example: Multi-Day All-Day Event
function createMultiDayEvent() {
var calendar = CalendarApp.getDefaultCalendar();
// Start date: November 10, 2026
var startDate = new Date("2026/11/10");
// End date: November 13, 2026 (*Important pitfall here! Explained below)
var endDate = new Date("2026/11/13");
// Create multi-day all-day event (title, startDate, endDate)
var event = calendar.createAllDayEvent("[Trip] Sapporo Business Trip & Branch Inspection", startDate, endDate);
Logger.log("Multi-day all-day event created!");
}
*The way end dates are handled has a major programmatic trap. We will cover this closely in STEP 6, so be sure not to miss it!
6. STEP 5: Level Up Your Workflow! Configure Optional Parameters (Location, Description, Guests)
In practical office workflows, you will often want to register more than just a title and time—such as a meeting room location, web conference link, agenda notes, and guest invitations.
By passing an { options } JavaScript object as the final argument to createEvent() or createAllDayEvent(), you can configure detailed metadata all at once!
Practical Code Example with Options
function createDetailedMeetingEvent() {
var calendar = CalendarApp.getDefaultCalendar();
var startTime = new Date("2026/10/15 14:00:00");
var endTime = new Date("2026/10/15 15:30:00");
// Prepare an options object with event details
var options = {
location: "Sapporo Office Meeting Room 1 (and Google Meet)",
description: "[Agenda]\n1. Q3 Performance Review\n2. Sapporo Office Facility Upgrades\n\n*Please notify #general on Slack if you will be late.",
guests: "tanaka@example.com, sato@example.com", // Comma-separated guest emails
sendInvites: true // Set to true to automatically send email invitations
};
// Pass options as the 4th argument!
var event = calendar.createEvent("[Sapporo Office] Monthly Report Meeting", startTime, endTime, options);
Logger.log("Event created with detailed options! ID: " + event.getId());
}
Key Optional Properties Overview
| Option Key | Type | Description | Example Value |
location |
String | Location of the event | "Kita 1-jo, Chuo-ku, Sapporo... Meeting Room 1" |
description |
String | Description / notes field (use \n for line breaks) |
"Meeting slides: https://..." |
guests |
String | Comma-separated email addresses of attendees to invite | "user1@example.com, user2@..." |
sendInvites |
Boolean | Whether to send email invitations to guests | true (Send) / false (Do not send) |
7. Top 5 Traps Beginners Face and How to Solve Them
Here are five common pitfalls and errors developers encounter when automating Google Calendar, along with straightforward solutions!
Trap 1: The Last Day Is Missing in Multi-Day createAllDayEvent
When trying to schedule a 3-day event from November 10 to November 12, writing the code like this will result in an event that only covers two days (Nov 10 to Nov 11).
// INCORRECT (Only registers for 11/10 - 11/11!)
var startDate = new Date("2026/11/10");
var endDate = new Date("2026/11/12");
calendar.createAllDayEvent("Sapporo Business Trip", startDate, endDate);
[Cause and Solution]
In createAllDayEvent(title, startDate, endDate), endDate represents “up to 00:00:00 of that day (the very start of the day)”. In other words, “up to midnight of November 12” effectively means “until the end of November 11”.
If you want to include November 12, specify November 13 (the day after your intended final day) as the end date. That is the correct Google Calendar specification!
// CORRECT (Registers across 11/10, 11/11, and 11/12)
var startDate = new Date("2026/11/10");
var endDate = new Date("2026/11/13"); // Specify the day AFTER the final day!
calendar.createAllDayEvent("Sapporo Business Trip", startDate, endDate);
Trap 2: Months Shift by 1 When Using JavaScript Numeric Date Constructors
When using JavaScript’s new Date(year, month, day) numeric constructor, remember that JavaScript months are zero-indexed (0 = January, 1 = February… 11 = December).
// INCORRECT: Intended October 15, but results in November 15!
var startTime = new Date(2026, 10, 15, 14, 0, 0);
// SOLUTION 1: Use string format to write '10' intuitively! (Recommended)
var startTime = new Date("2026/10/15 14:00:00");
// SOLUTION 2: When using numeric arguments, subtract 1 from the desired month
var startTime = new Date(2026, 9, 15, 14, 0, 0); // 9 represents October
To prevent unexpected date bugs, we highly recommend beginners use the string date format: new Date("YYYY/MM/DD HH:mm:ss")!
Trap 3: End Time Is Before Start Time Error
If you accidentally reverse the start and end times or set them to the exact same timestamp, Google Calendar throws an exception:
Exception: Invalid args: endDate cannot be before startDate
[Solution]
Double-check your calculation logic to make sure endTime is always set to a time strictly after startTime (at least 1 minute later).
Trap 4: Events Shift by Several Hours Due to Time Zone Mismatches
If you scheduled an event for 2:00 PM but it appears at 5:00 AM on your calendar, your GAS project time zone might be set to UTC (Coordinated Universal Time).
[Solution]
- Click the Gear icon (Project Settings) in the left sidebar of the GAS editor.
- Check the box for “Show ‘appsscript.json’ manifest file in editor”.
- Return to the code editor, open
appsscript.json, and confirm that"timeZone"matches your local region (e.g.,"timeZone": "Asia/Tokyo"or"America/New_York"). Update and save if necessary.
Trap 5: Permission Errors When Writing to Read-Only Calendars
If you attempt to call createEvent() on a shared calendar where you only have view access, you will encounter a permission error:
Exception: You do not have permission to perform that action.
[Solution]
Open the Google Calendar web app, navigate to the target calendar’s “Settings and sharing”, and verify that your account has been granted “Make changes to events” or full “Make changes and manage sharing” permissions.
8. Summary and What’s Next
In this tutorial, we mastered how to automatically create Google Calendar events using Calendar.createEvent() and Calendar.createAllDayEvent()!
Quick Recap of Key Takeaways
- Use
createEvent(title, startTime, endTime)for timed appointments. - Use
createAllDayEvent(title, date)for single-day full-day events. - Use the optional
{ location, description, guests }object to add rooms, notes, and send invites. - For multi-day all-day events, set
endDateto the day after your intended final day. - Constructing dates via string format like
new Date("2026/10/15 14:00:00")avoids 0-indexed month traps.
When combined with spreadsheet data, you can build full-fledged automated tools that register dozens or hundreds of calendar events in seconds!
In Part 78, we will explore the reverse operation: reading existing Google Calendar events using Calendar.getEvents()!
It is an essential technique for checking schedule availability and automating meeting audits, so stay tuned!
