JavaScript .setDate()
Anonymous contributor
Published Jun 15, 2023
Contribute to Docs
The .setDate() method changes the day of the month according to local time.
Syntax
myDate.setDate()
The .setDate() method changes the day of the month of a provided date according to local time.
Example
In the example below, the myDate variable takes the provided date and then the .setDate() method is applied to return a modified date.
const myDate = new Date('2023-01-01');myDate.setDate(24);console.log(myDate.getDate());
This results in the following output:
24
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours