This feature is not Baseline because it does not work in some of the most widely-used browsers.
The with() method of Temporal.PlainDate instances returns a new Temporal.PlainDate object representing this date with some fields replaced by new values. Because all Temporal objects are designed to be immutable, this method essentially functions as the setter for the date's fields.
To replace the calendarId property, use the withCalendar() method instead.
with(info) with(info, options)
infoAn object containing at least one of the properties recognized by Temporal.PlainDate.from() (except calendar): day, era and eraYear, month, monthCode, year. Unspecified properties use the values from the original date. You only need to provide one of month or monthCode, and one of era and eraYear or year, and the other will be updated accordingly.
options OptionalAn object containing the following property:
overflow OptionalA string specifying the behavior when a date component is out of range. Possible values are:
"constrain" (default)The date component is clamped to the valid range.
"reject"A RangeError is thrown if the date component is out of range.
A new Temporal.PlainDate object, where the fields specified in info that are not undefined are replaced by the corresponding values, and the rest of the fields are copied from the original date.
TypeErrorThrown in one of the following cases:
info is not an object.options is not an object or undefined.RangeErrorThrown in one of the following cases:
monthCode is never a valid month code in this calendar.options.overflow is set to "reject".const date = Temporal.PlainDate.from("2021-07-06");
const newDate = date.with({ day: date.daysInMonth });
console.log(newDate.toString()); // 2021-07-31
const nextDecade = date.with({ year: date.year + 10 });
console.log(nextDecade.toString()); // 2031-07-06
For more examples, see the documentation for the individual properties that can be set using with().
| Specification |
|---|
| Temporal> # sec-temporal.plaindate.prototype.with> |
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
with |
144 | 144 | 139 | No | No | 144 | 139 | No | No | No | 144 | No | ? | 1.40 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate/with