setDate

Commons
stable

Return a new Date with the day-of-month replaced by the given value. The original date is never mutated.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

date
required
Date
The source date. It is cloned before the day is updated.
day
required
number
The day-of-month to set (1–31). Values outside the month range are normalised by the JS Date constructor.

API

Return value

The value returned by this util.

A new Date object with the specified day-of-month.

Usage

Examples

Ready-to-paste usage snippets.

Change the day while keeping month and year

typescript