Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Created July 30, 2022 00:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tanaikech/be6ef51a402aacb9fa24277dffed63bc to your computer and use it in GitHub Desktop.
Save tanaikech/be6ef51a402aacb9fa24277dffed63bc to your computer and use it in GitHub Desktop.
Retrieving Names of Month and Day of Week using Google Apps Script

Retrieving Names of Month and Day of Week using Google Apps Script

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"]

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment