How to Add Days to Current Date in JavaScript
Topic: JavaScript / jQueryPrev|Next
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:
Example
Try this code »// 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.
Example
Try this code »// 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);
Related FAQ
Here are some more FAQ related to this topic: