JavaScript Date setDate()
Example 1
Set the day of the month in a specified date:
const d = new Date("2025-01-15");
d.setDate(20);
Try it Yourself »
d.setDate(20);
Description
setDate()
sets the day of the month of a date.
Example 2
Set the day of the month to the last day of the previous month:
const d = new Date("2025-01-15");
d.setDate(0);
Try it Yourself »
d.setDate(0);
Example 3
Set the day to the first day in the next month:
const d = new Date("2025-01-15");
d.setDate(32);
Try it Yourself »
d.setDate(32);
Syntax
Date.setDate(day)
Parameters
day
An integer representing the day (1 to 31).
Higher and lower values are handeled with date maths:
- 0 gives the last day of the previous month
- -1 gives the day before the last day of the previous month
- 32 gives the first day of the next month (if 31 days)
- 41 gives the tenth day of the next month (if 31 days)
Return Value
NONE
Changes the Date object in place.
Browser Support
setDate()
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |