[i]Learn· Representing dates & times
Plain year-months and month-days
You can remove further information from plain dates. Sometimes you don't even care about the whole year-month-day triple; you might only need a whole month in a year, or a recurring date in every year. The Temporal.PlainYearMonth and Temporal.PlainMonthDay objects provide such functionalities.
// A special whole month
const prideMonth2026 = Temporal.PlainYearMonth.from({ year: 2026, month: 6 });
// A special calendar date for every year
const remembranceDay = Temporal.PlainMonthDay.from({ month: 11, day: 11 });
Year-months and month-days still store a full plain date internally, which is mostly used to deal with non-ISO calendars. Read the two classes' references, especially Temporal.PlainYearMonth.from() and Temporal.PlainMonthDay.from(), for more details about the reference day and what it does.
You can also convert back-and-forth between year-months/month-days and dates.
const juneteenth2026 = prideMonth2026.toPlainDate({ day: 19 }); // 2026-06-19
const remembranceDay2026 = remembranceDay.toPlainDate({ year: 2026 }); // 2026-11-11
const mdnCreationMonth = mdnCreationDate.toPlainYearMonth(); // 2020-09
const bastilleDay = bastilleFall.toPlainDate().toPlainMonthDay(); // 07-14scratch
[>_]Terminal
Output appears here when you press Run.
$ ▌