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.
API
Parameters
Input parameters accepted by this util.
- daterequiredDate
- The source date. It is cloned before the day is updated.
- dayrequirednumber
- 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