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 266 views
1 answer 211 views
211 views asked Mar 22, 2022 by avibootz
1 answer 208 views
208 views asked Mar 21, 2022 by avibootz
1 answer 229 views
229 views asked Mar 21, 2022 by avibootz
...