loading

How to add days to date in javascript

To add days to a JavaScript date object, you can use the setDate() method to modify the day of the month. Here’s an example:

// create a new date object
var date = new Date();

// add 7 days to the date
date.setDate(date.getDate() + 7);

// output the new date as a string
console.log(date.toDateString());

In this example, we create a new Date object and then use the setDate() method to add 7 days to the current day of the month. We use the getDate() method to get the current day of the month and add 7 to it, and then pass that value to the setDate() method. Finally, we output the new date as a string using the toDateString() method.

You can replace 7 it with any number of days you want to add to the date.

About Author

x

Order for website design

Help :