How to calculate the date six months from the current date in TypeScript

1 Answer

0 votes
function addMonthsToDate(months: number, date = new Date()): Date {
    date.setMonth(date.getMonth() + months);
 
    return date;
}
 
 
console.log(addMonthsToDate(6).toDateString()); 

   
   
/*
run:
   
"Fri Dec 12 2025" 
   
*/

 



answered Jun 12 by avibootz
...