Sometimes, we want to get the date 7 days after today with JavaScript.
In this article, we’ll look at how to get the date 7 days after today with JavaScript.
How to get the date 7 days after today with JavaScript?
To get the date 7 days after today with JavaScript, we can use the getDate
and setDate
methods.
For instance, we write
const date = new Date();
date.setDate(date.getDate() + 7);
console.log(date);
to create a Date
object with the current date and time.
Then we call getDate
to get the current day of the month.
And then we call setDate
with the current day of the month plus 7 to set date
to 7 days after today.
Conclusion
To get the date 7 days after today with JavaScript, we can use the getDate
and setDate
methods.