JavaScript setDate()Method
Definition and Usage
The setDate() method sets the day of a month.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the setDate() method.
Syntax
Date.setDate(day)
Parameter Values
| Parameter | Description |
|---|---|
| day | Required. A numeric value representing the day of a month (1 - 31):
If the current month has 31 days:
If the current month has 30 days:
|
Return Value
| Type | Description |
|---|---|
| Number | The number of milliseconds between midnight January 1, 1970 and the adjusted date. Before ECMAScript standardization, this method did not return anything. |
Technical Details
| JavaScript Version: | 1.0 |
|---|
More Examples
Example
Set the day of a month to the last day of the previous month:
var d = new Date();
d.setDate(0);
d.setDate(0);
dOutput:
Try it Yourself »
Example
In this example, we will set the day of the current month to 15 using the setDate() method:
var d = new Date("July 21, 1983 01:15:00");
d.setDate(15);
d.setDate(15);
dOutput:
Try it Yourself »
Other Extensions
JavaScript Date Object