Date.prototype.setDate
Sets the day of the month — handy for adding and subtracting days.
Available since: ES1
Syntax
date.setDate(day)Parameters
| Parameter | Type | Description |
|---|---|---|
| day | number | The day of the month. 0 is the last day of the previous month, 32 rolls into the next one. |
Return value
numberThe new timestamp. The object itself changes.
Examples
In 20 days — rolling into the next month:
const date = new Date(2026, 2, 15);
date.setDate(date.getDate() + 20);
console.log(date.getMonth() + 1, date.getDate());Output:
4 4A week ago:
const date = new Date(2026, 2, 3);
date.setDate(date.getDate() - 7);
console.log(date.getMonth() + 1, date.getDate());Output:
2 24Notes
Overflow is handled automatically: the month and year are recalculated. It is the most reliable way to add days, including across daylight saving changes.
See also
- Date.prototype.getDate — Returns the day of the month.
- Date.prototype.setMonth — Sets the month.
Related recipes
In the tutorial
- Dates and time — The Date object in JavaScript: creating a date, reading the year, month and day, changing a date, the difference between dates and the ISO format.