JavaScript setDate() method
Example
Set the day of the month:
var d = new Date();
d.setDate(15);
d Output result:
Try it »
Definition and Usage
The setDate() method is used to set the day of the month.
Browser support





All major browsers support the setDate() method
Syntax
Date
.setDate(
day
)
Parameter value
| Parameters | Description |
|---|---|
| day | Required.
A value (1 to 31) representing a day of the month: |
If the current month has 31 days:
- 32 is the first day of the next month
If the current month has 30 days:
- 32 is the second day of the next month
Return Value
| Type | Description |
|---|---|
| Number | The number of milliseconds from midnight January 1, 1970 to the adjusted date. Before ECMAScript standardization, this method returned nothing. |
Technical Details
| JavaScript version: | 1.0 |
|---|
More examples
Example
Set the day of the month to the last day of the previous month:
var d = new Date();
d.setDate(0);
d Output result:
Try it »
Example
In this example, we set the current month's day to 15 using the setDate() method:
var d = new Date("July 21, 1983 01:15:00");
d.setDate(15);
d Output result:
Try it »
JavaScript Date object