How to add 6 months to current date in JavaScript

1 Answer

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

  	return date;
}


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

  
  
  
/*
run:
  
"Thu Sep 22 2022"
  
*/

 



answered Mar 22, 2022 by avibootz
edited Jun 12, 2025 by avibootz
...