How to add months to a date in Node.js

1 Answer

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

  	return date;
}


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

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


  
  
  
  
/*
run:
  
Thu Nov 17 2022
  
*/

 



answered Mar 22, 2022 by avibootz

Related questions

1 answer 271 views
1 answer 217 views
217 views asked Mar 22, 2022 by avibootz
1 answer 215 views
215 views asked Mar 21, 2022 by avibootz
1 answer 231 views
231 views asked Mar 21, 2022 by avibootz
...