Sometimes, we want to add 2 weeks to a JavaScript date.
In this article, we’ll look at how to add 2 weeks to a JavaScript date.
How to add 2 weeks to a JavaScript date?
To add 2 weeks to a JavaScript date, we use the Date constructor.
For instance, we write
const date = new Date();
date.setDate(date.getDate() + 14);
to create a date object.
Then we call getDate to get the current date of the month.
Next, we call setDate with the current date of the month plus 14 to set the date to the date of the month 14 days from today.
Conclusion
To add 2 weeks to a JavaScript date, we use the Date constructor.