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 141 views
1 answer 106 views
106 views asked Mar 29, 2022 by avibootz
1 answer 134 views
1 answer 127 views
127 views asked Mar 25, 2022 by avibootz
1 answer 119 views
1 answer 148 views
1 answer 196 views
...