How to add 6 months to a date in JavaScript

1 Answer

0 votes
function addMonthsToDate(months, date = new Date()) {
  	date.setMonth(date.getMonth() + months);

  	return date;
}


const date = new Date('2022-02-17');

console.log(addMonthsToDate(6, date).toDateString()); 


  
  
  
  
/*
run:
  
"Wed Aug 17 2022"
  
*/

 



answered Mar 22, 2022 by avibootz

Related questions

1 answer 235 views
1 answer 173 views
173 views asked Mar 29, 2022 by avibootz
1 answer 225 views
1 answer 202 views
202 views asked Mar 25, 2022 by avibootz
1 answer 186 views
1 answer 228 views
1 answer 270 views
...