How to add weeks to date using javascript?

You can do this :

const numWeeks = 2;
const now = new Date();
now.setDate(now.getDate() + numWeeks * 7);

or as a function

const addWeeksToDate = (dateObj,numberOfWeeks) => {
  dateObj.setDate(dateObj.getDate()+ numberOfWeeks * 7);
  return dateObj;
}

const numberOfWeeks = 2 
console.log(addWeeksToDate(new Date(), 2).toISOString());

You can see the fiddle here.

According to the documentation in MDN

The setDate() method sets the day of the Date object relative to the beginning of the currently set month.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)