Date.prototype.setUTCDate()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
ThesetUTCDate() method ofDate instances changes the day of the month for this date according to universal time.
In this article
Try it
const event = new Date("August 19, 1975 23:15:30 GMT-3:00");console.log(event.getUTCDate());// Expected output: 20event.setUTCDate(19);console.log(event.getUTCDate());// Expected output: 19Syntax
setUTCDate(dateValue)Parameters
dateValueAn integer from 1 to 31 representing the day of the month.
Return value
Changes theDate object in place, and returns its newtimestamp. IfdateValue isNaN (or other values that getcoerced toNaN, such asundefined), the date is set toInvalid Date andNaN is returned.
Description
If thedateValue is outside of the range of date values for the month,setDate() will update theDate object accordingly.
For example, if 0 is provided fordateValue, the date will be set to the last day of the previous month. If you use 40 fordateValue, and the month stored in theDate object is June, the day will be changed to 10 and the month will be incremented to July.
If a negative number is provided fordateValue, the date will be set counting backwards from the last day of the previous month. -1 would result in the date being set to 1 day before the last day of the previous month.
Examples
>Using setUTCDate()
const theBigDay = new Date();theBigDay.setUTCDate(20);Specifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-date.prototype.setutcdate> |