This is a sample script for retrieving the names of month and day of week using Google Apps Script.
I think that you might have a case that you want to retrieve the names of month and day of week using Google Apps Script. This sample script retrieves them using a simple script.
Using Utilities.formatDate
of Google Apps Script, the names of month and day of week can be retrieved using a simple script.
Sample script 1
This sample script retrieves the names of month.
const timeZone = Session.getScriptTimeZone();
const res = [...Array(12)].map((_, i) =>
Utilities.formatDate(new Date(2022, i, 1), timeZone, "MMMM")
);
When this script is run, the following result is obtained.
["January","February","March","April","May","June","July","August","September","October","November","December"]
When you change MMMM
to MMM
, you can retrieve the following result.
["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
Sample script 2
This sample script retrieves the names of day of week.
const timeZone = Session.getScriptTimeZone();
const res = [...Array(7)].map((_, i) =>
Utilities.formatDate(new Date(2022, 1, i - 1), timeZone, "EEEE")
);
When this script is run, the following result is obtained.
["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
When you change EEEE
to EEE
, you can retrieve the following result.
["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]