Last Updated : 11 Jul, 2025
The setDate()
method in JavaScript is used to set the day of the month for a specified date object, according to local time. It allows you to update the day part of the date without changing other parts like month and year.
dateObj.setDate(date_Value);Date setDate() Parameter
This method accepts a single parameter as mentioned above and described below:
This method returns the number of milliseconds between the date object and midnight of January 1, 1970
Note: DateObj is a valid Date object created using Date() constructor in which we want to set the date of a month.
JavaScript Date setDate() Method Examples Example 1: Updating Day of the Month with JavaScript's setDate()In this example, we create a new Date object representing February 15, 2022. Then, we use setDate(20)
to update the day of the month to the 20th. The resulting date object now represents February 20, 2022.
let date = new Date('2022-02-15');
console.log(date);
date.setDate(20);
console.log(date);
2022-02-15T00:00:00.000Z 2022-02-20T00:00:00.000ZExample 2: Adding 7 Days to Current Date in JavaScript
A Date object date
is initialized with the current date. setDate()
method is used with getDate()
to add 7 days. The updated date, representing the date 7 days later, is logged.
let date = new Date();
console.log(date); // Output: Current date and time
date.setDate(date.getDate() + 7); // Adding 7 days to the current date
console.log(date); // Output: Date after adding 7 days
2024-03-08T11:22:29.251Z 2024-03-15T11:22:29.251Z
We have a complete list of Javascript Date Objects, to check those please go through this Javascript Date Object Complete reference article.
Supported Browsers:The browsers supported by the JavaScript Date setDate() method are listed below:
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4