format

format(d: date, pattern: text) 🡒 text, const pure function

The format function provides a small formatting framework intended to convert a date its text counterpart. The first argument is the date to be formatted. The second argument is the pattern, a sequence of specifiers used to specify the intended formatting.

d = date(2022, 9, 26)

show summary "Formats" a1a3 with
  format(d, "yyyy-MM-dd")  // 2022-09-26
  format(d, "M/dd/yy")     // 9/29/22
  format(d, "MMM d, yyyy") // Sept 26, 2022

The list of supported specifiers is given below.

SpecifierDescriptionSourceMatch
yThe year from 0 to 99.2019-06-0519
y2001-01-281
yyThe year from 00 to 99.2001-06-0519
yy2001-01-2801
yyySame as yyyy
yyyyThe 4-digit year.2019-06-052019
yyyy2001-01-282001
MThe month from 1 to 12.2019-12-0512
M2001-01-281
MMThe month from 01 to 12.2019-12-0512
MM2001-01-2801
MMMThe abbreviated month.2019-12-05Dec
MMM2001-01-28Jan
MMMMThe full-word month.2019-12-05December
MMMM2001-01-28January
dThe day from 1 to 31.2019-12-055
d2001-01-2828
ddThe day from 01 to 31.2019-12-0505
dd2001-01-2828
dddThe abbreviated weekday.2022-09-26Mon
ddddThe full-word weekday.2022-09-26Monday

Any other character, that isn’t listed as a specifier, is written to the formatted output.

Some characters are reserved for future use: w, v and \.