🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #187

Temporal PlainYearM

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.

Temporal Map


How to Create a PlainYearMonth Object

An PlainYearMonth object can be created in different ways:

Col 1 Col 2
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);

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});

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");

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);

Convert to PlainTime

Example

const yearMonth = new Temporal.PlainYearMonth(2026, 5);

const date = yearMonth.toPlainDate({ day: 17 });

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})

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)

Note: Learn More: JavaScript Temporal Arithmetic


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 });

All PlainYearMonth Methods

Col 1 Col 2
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

Col 1 Col 2
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

Want to go beyond the notes?

Join CodingNow 2.0's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Temporal PlainYearM – FAQs

Quick answers about learning Temporal PlainYearM in JavaScript.

This free note from CodingNow 2.0 explains Temporal PlainYearM in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on CodingNow 2.0, including Temporal PlainYearM, is 100% free with no signup required.
With focused practice, most students grasp Temporal PlainYearM in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now