How to add months to a date in TypeScript

1 Answer

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

  	return date;
}


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

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


  
  
  
  
/*
run:
  
"Thu Aug 11 2022" 
  
*/

 



answered Mar 22, 2022 by avibootz
...