Skip to content

Instantly share code, notes, and snippets.

@TheGreatGaspy
Forked from tanaikech/submit.md
Created July 26, 2023 16:49
Show Gist options
  • Save TheGreatGaspy/b70ffc0ee5942287d30a1bf1539f43db to your computer and use it in GitHub Desktop.
Save TheGreatGaspy/b70ffc0ee5942287d30a1bf1539f43db 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