JavaScript Date setDate()
Definition and Usage
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();
d.setDate(0);
Try it Yourself »
Example 3
Set the day of the month in a specified date:
const d = new Date("July 21, 1983 01:15:00");
d.setDate(15);
Try it Yourself »
Browser Support
setDate()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
Date.setDate(day)
Parameters
day | An integer representing the day (1 to 31).
Higher and lower values are handeled with date maths:
|
Return Value
A number. Number of milliseconds between the date and January 1, 1970 00:00:00 UTC. |