JavaScript Reference ยท Date and Intl
Date.prototype.setDate()
Reference for JavaScript setDate() and the other Date setters: setMonth, setFullYear, setHours and UTC versions, with rollover rules and month-end traps.
setDate() changes the day of the month of a Date, in local time. It belongs to a family of setters (setFullYear(), setMonth(), setHours(), setMinutes(), setSeconds(), setMilliseconds(), setTime(), and the setUTC... versions) that all mutate the date object in place.
Setters accept values outside the normal range and roll them over. Setting the day to 32 in January moves into February; setting it to 0 gives the last day of the previous month. This makes date math easy, but it also causes surprises at the end of a month.
const d = new Date(2026, 0, 31); d.setDate(d.getDate() + 5); // February 5, 2026
Try it
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Syntax
date.setDate(day) date.setMonth(monthIndex, day) date.setFullYear(year, monthIndex, day) date.setHours(hours, minutes, seconds, milliseconds) date.setMinutes(minutes, seconds, milliseconds) date.setSeconds(seconds, milliseconds) date.setMilliseconds(milliseconds) date.setTime(timestamp)
| Name | Description |
|---|---|
day |
Day of the month. 0 is the last day of the previous month; values above the month length roll into the next month. |
monthIndex |
Month starting at 0. Values outside 0 to 11 roll the year. |
year, hours, minutes, seconds, milliseconds |
The value to set. Optional trailing arguments set the smaller parts at the same time. |
timestamp |
For setTime(): milliseconds since the Unix epoch. |
Return value: the new timestamp of the date (a number), not the date. Because of that, setters cannot be chained. If the result is not a valid date, the return value is NaN.
Exceptions: none for out-of-range values.
Usage notes
- They mutate. Copy first when other code holds a reference:
const next = new Date(date); next.setDate(...). - Return value is a number.
new Date().setDate(5)gives a timestamp; do not assign it back to your date variable. - Month-end overflow. Adding a month to January 31 does not produce "the end of February"; it produces March 2 or 3. Use a helper like
addMonths()above when this matters. - Local time rules.
setDate()keeps the local clock time, so on a day when daylight saving time changes, "tomorrow at 09:00" stays 09:00 even though 23 or 25 hours have passed. That is usually what people want. Adding24 * 60 * 60 * 1000to the timestamp does not behave this way. - UTC versions (
setUTCDate(),setUTCHours(), ...) act on UTC parts and are free of DST effects. - Invalid dates stay invalid. Calling a setter on an Invalid Date returns
NaN, exceptsetTime()and the year setters, which can repair it. - Setting several parts at once (
setHours(9, 30, 0, 0)) is shorter and avoids intermediate states. setYear()is deprecated; usesetFullYear().
Browser support
All setters are available in every browser and runtime.