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

JavascriptWeb DevelopmentFront End Technology

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>
raja
Published on 29-Jan-2018 10:27:30
Advertisements