How to calculate the date six months from the current date in Node.js

1 Answer

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

console.log("Date six months from now:", addMonthsToDate(6).toDateString());



/*
run:

Date six months from now: Fri Dec 12 2025

*/

 



answered Jun 12, 2025 by avibootz
...