JavaScript PlainYearMonth
The Temporal.PlainYearMonth Object
The Temporal.PlainYearMonth object is a year and month object.
It represents the year and month of an ISO 8601 calendar without day or time.
Example: 2026-05.
How to Create a PlainYearMonth Object
An PlainYearMonth object can be created in different ways:
| From | Code |
|---|---|
| Parameters | new Temporal.PlainYearMonth(param) |
| Object | Temporal.PlainYearMonth.from(object) |
| ISO / RFC 9557 | Temporal.PlainYearMonth.from(RFC 9557) |
Create a PlainYearMonth with new
The new PlainYearMonth() constructor creates a new PlainYearMonth object
with integers as input parameters.
Example
// Create a PlainYearMonth object
const date = new Temporal.PlainYearMonth(2026, 5);
Try it Yourself »
PlainYearMonth from(object)
The from() method creates a new PlainYearMonth object with an
object as input parameter.
Example
// Create a PlainYearMonth object
const date = new Temporal.PlainYearMonth({year:2026, month:5});
Try it Yourself »
PlainYearMonth from(RFC 9557)
The from() method creates a new PlainYearMonth object with an
ISO / RFC 9557 string as input parameter.
Examples
// Create a PlainYearMonth object
const date = Temporal.PlainYearMonth.from("2025-05");
Try it Yourself »
// Create a PlainYearMonth object
const date = Temporal.PlainYearMonth.from("2025-05-17");
Try it Yourself »
Note that the day input is ignored in the last example.
Temporal.PlainYearMonth Properties
Display All PlainYearMonth Properties
const date = new Temporal.PlainYearMonth(2026, 5);
Try it Yourself »
Convert to PlainTime
Example
const yearMonth = new Temporal.PlainYearMonth(2026, 5);
const date = yearMonth.toPlainDate({ day: 17 });
Try it Yourself »
PlainYearMonth add() and subtract()
The add() method accept a duration object as input.
Example
// Create a new PlainYearMonth object
const d1 = Temporal.PlainYearMonth.from("2026-05");
// Add a duration
const d2 = d1.add({years:2, months:2})
Try it Yourself »
All temporal objects have their own add() method:
- duration.add(duration)
- instant.add(duration)
- plaindate.add(duration)
- plaintime.add(duration)
- plainyearmonth.add(duration)
- plainmonthday.add(duration)
- plaindatetime.add(duration)
- zoneddatetime.add(duration)
All temporal objects have their own subtract() method:
- duration.subtract(duration)
- instant.subtract(duration)
- plaindate.subtract(duration)
- plaintime.subtract(duration)
- plainyearmonth.subtract(duration)
- plainmonthday.subtract(duration)
- plaindatetime.subtract(duration)
- zoneddatetime.subtract(duration)
Learn More:
The with() Method
The with() method returns a new PlainYearMonth object with specified field(s) replaced.
Example
// Create a PlainYearMonth object
const date = Temporal.PlainYearMonth.from("2026-05");
// Replace month
const newDate = date.with({ month:12 });
Try it Yourself »
All PlainYearMonth Methods
| Constructing | Description |
|---|---|
| from() | Creates a PlainYearMonth object from an object or a string |
| new (constructor) | Creates a PlainYearMonth object from integer parameters |
| Arithmetic | |
| add() | Returns a new PlainYearMonth with a duration added |
| subtract() | Returns a new PlainYearMonth with a duration subtracted |
| Comparing | |
| compare() | Returns -1, 0, or 1 from comparing two dates |
| equals() | Returns true if two dates are identical |
| since() | Returns the difference since another date |
| until() | Returns the difference until another date |
| Converting | |
| toPlainDate() | Returns a new PlainDate object |
| with() | Returns a new PlainYearMonth with fields modified |
| Formatting | |
| toJSON() | Returns an RFC 9557 format string for JSON serialization |
| toLocaleString() | Returns a language-sensitive representation of the date |
| toString() | Returns an RFC 9557 format string representation |
| valueOf() | TypeError (temporals cannot be converted to primitives) |
All PlainYearMonth Properties
| Property | Description |
|---|---|
| calendarID | Calendar system identifier ("iso8601") |
| daysInMonth | The total number of days in that month |
| daysInYear | The total number of days in that year |
| era | The era name of the calendar, if applicable ("gregory") |
| eraYear | The year within the era, if applicable |
| inLeapYear | A boolean indicating if the date falls in a leap year |
| month | The month as an integer (1-12) |
| monthCode | A calendar-specific string code for the month ("M01") |
| monthsInYear | The total number of months in that year |
| year | The year as an integer |