I was looking for Japanese holiday data to create a national holiday table in a database.
In the end, I was able to obtain the data in CSV format that I wanted most from the following site (thanks to the author), but I took a long detour to get there, so here is the memo.
Introduction.
If you search for something like "Japan Holidays Data" to get Japanese holidays, you will find the Cabinet Office website at the top of the list.
You can download CSV files, and in a way, it's an official site, so I was just about to use it.
- No historical data.
- No data on compensatory holidays
It turns out that this is not usable.
I see that it was discussed in the past as "Sad news] The Cabinet Office's "National Holidays" CSV is terrible [Updated]." and it's been 2 years since then and there seems to be no improvement...
Use Google Calendar
There are other sites that list various holidays, but I was somewhat concerned, so I decided to get the data from a more reliable source, Google Calendar.
To add Japanese holidays to Google Calendar, go to the gear icon in the calendar
- [Settings]-[Add Calendar]-[Find Calendars of Interest]-[Holidays]-[Local Holidays]-[Japanese Holidays]
This can be done at
However, the "Japanese Holidays" calendar in Google Calendar cannot be exported and can barely be downloaded in "iCal" format only.
Converting "iCal" files to CSV.... I reconsidered something different.
Using Outlook Schedules
Since Outlook also has a Japanese holiday calendar like Google Calendar, I thought of getting it from Microsoft's Outlook.
The Japanese Holidays Calendar is done from the Office365 web. There is a way to add it in the application Outlook, but we do not recommend that you do so, as that will import the Japanese holiday calendar as your own calendar.
To add Japanese holidays to your Office365 calendar, from the bottom of the calendar list on the left side of Outlook
- [Find a schedule]-[Holidays]-[Japan]
This can be done at
Next is the export, but this time it cannot be done from the Office365 web, but from the app Outlook.... It's complicated...
Exporting an appointment calendar from Outlook in the app is
- [File]-[Open/Export]-[Import/Export]-[Export to File]-[Text File (comma delimited)
This can be done at
Find API
The above was my initial goal of acquiring CSV data of Japanese national holidays, but when I searched for "Japanese national holidays API," I found the API site for acquiring Japanese national holidays from Google Calendar, which I described at the beginning of this article.
And it's easy to use and doesn't output any unnecessary information. I wish I had found this first.
Get it with Google Apps Script
API, but there are many examples of getting it from Google Calendar with Google Apps Script.
You may also want to know how to get it yourself using Google Apps Script.
To output to a Google spreadsheet, do the following
Script editor for Google Spreadsheets
Results
Code.gs
function myFunction() { const sheet = SpreadsheetApp.getActiveSheet(); const start = new Date('2019/01/01 00:00:00'); const end = new Date('2020/01/01 00:00:00'); const cal = CalendarApp.getCalendarById('ja.japanese#holiday@group.v.calendar.google.com'); const events = cal.getEvents(start, end); const week = ["日", "月", "火", "水", "木", "金", "土"]; var out = [['曜日','日付','イベント']]; for(var i=0, len=events.length; i<len; ++i){ var e = events[i]; out.push([ week[e.getStartTime().getDay()], e.getStartTime().toLocaleDateString(), e.getTitle() ]); } sheet.getRange(1,1,out.length,3).setValues(out); }