How to add a number of months to a date using JavaScript?


To add a number of months to a date, first get the month using getMonth() method and add a number of months.

Example

You can try to run the following code to add a number of months

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         var d, e;
         d = new Date();
         document.write(d);

         e = d.getMonth()+1;
         document.write("<br>Incremented month = "+e);
      </script>
   </body>
</html>

Updated on: 07-Jan-2020

473 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements