Temporal.PlainDateTime.prototype.with()

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The with() method of Temporal.PlainDateTime instances returns a new Temporal.PlainDateTime object representing this date-time 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-time's fields.

To replace the calendarId property, use the withCalendar() method instead.

Syntax

js
with(info)
with(info, options)

Parameters

info

An object containing at least one of the properties recognized by Temporal.PlainDateTime.from() (except calendar): day, era and eraYear, hour, microsecond, millisecond, minute, month, monthCode, nanosecond, second, year. Unspecified properties use the values from the original date-time. 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 Optional

An object containing the following property:

overflow Optional

A 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.

Return value

A new Temporal.PlainDateTime 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-time.

Exceptions

TypeError

Thrown in one of the following cases:

  • info is not an object.
  • options is not an object or undefined.
RangeError

Thrown in one of the following cases:

  • The provided properties that specify the same component are inconsistent.
  • The provided non-numerical properties are not valid; for example, if monthCode is never a valid month code in this calendar.
  • The provided numerical properties are out of range, and options.overflow is set to "reject".
  • The result is not in the representable range, which is ±(108 + 1) days, or about ±273,972.6 years, from the Unix epoch.

Examples

Using with()

js
const dt = Temporal.PlainDateTime.from("2021-07-01T12:34:56");
const newDT = dt.with({ hour: 13 });
console.log(newDT.toString()); // "2021-07-01T13:34:56"
const newDT2 = dt.with({ month: 2, day: 22, millisecond: 222 });
console.log(newDT2.toString()); // "2021-02-22T13:34:56.222"
const nextDecade = dt.with({ year: dt.year + 10 });
console.log(nextDecade.toString()); // "2031-07-01T13:34:56"

For more examples, see the documentation for the individual properties that can be set using with().

Specifications

Specification
Temporal
# sec-temporal.plaindatetime.prototype.with

Browser compatibility

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
Chrome – Full support
Chrome 144 (Release date: 2026-01-13)
footnote Full support
Edge – Full support
Edge 144 (Release date: 2026-01-21)
footnote Full support
Firefox – Full support
Firefox 139 (Release date: 2025-05-27)
footnote Full support
Opera – Full support
Opera 128 (Release date: 2026-02-26)
footnote Full support
Safari – No support
Safari
footnote
footnote See bug 223166
Chrome Android – Full support
Chrome Android 144 (Release date: 2026-01-13)
footnote Full support
Firefox for Android – Full support
Firefox for Android 139 (Release date: 2025-05-27)
footnote Full support
Opera Android – Full support
Opera Android 95 (Release date: 2026-02-11)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote
footnote See bug 223166
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 144 (Release date: 2026-01-13)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote
footnote See bug 223166
Bun – No support
Bun
footnote No support
Deno – Full support
Deno 2.7 (Release date: 2026-02-25)
footnote Full support
Node.js – No support
Node.js
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also