Q:

How to Add Days to Current Date in JavaScript

0

How to Add Days to Current Date in JavaScript

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the setDate() Method

You can simply use the setDate() method to add number of days to current date using JavaScript. Also note that, if the day value is outside of the range of date values for the month, setDate() will update the Date object accordingly (e.g. if you set 32 for August it becomes September 01).

Let's try out the following example to understand how it actually works:

// Get current date
var date = new Date();

// Add five days to current date
date.setDate(date.getDate() + 5);

console.log(date);

Similarly, you can also add number of days to a particular date in JavaScript.

// Specific date
var date = new Date('August 21, 2021 16:45:30');

// Add ten days to specified date
date.setDate(date.getDate() + 10);

console.log(date);

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Compare Two Dates in JavaScript... >>
<< How to Set Default Parameter Value for a JavaScrip...