Tutorialspoint

MomentJS Subtract

<html>
   <head>
      <title>MomentJS - Subtract Method</title>
      <script type="text/JavaScript"    src="https://MomentJS.com/downloads/moment.js"></script>
      <style>
         div {
            border: solid 1px #ccc;
            padding:10px;
            font-family: "Segoe UI",Arial,sans-serif;
            width: 75%;
         }
      </style>
   </head>
   <body>
      <h1>MomentJS - Subtract Method</h1>
      <div style="font-size:25px" id="currentdate"></div>
      <br/>
      <br/>
      <div style="font-size:25px" id="changeddate"></div>
      <br/>
      <br/>
      <div style="font-size:25px" id="changeddate1"></div>
      <br/>
      <br/>
      <div style="font-size:25px" id="changeddate2"v</div>
      <script type="text/JavaScript">
         var day = moment();
         document.getElementById("currentdate").innerHTML = "Current Date: " + day._d;
         var changeddate = moment().subtract(5, 'days').subtract(2, 'months');
         document.getElementById("changeddate").innerHTML = "Subtracting 5 days and 2 month using chaining method: " + changeddate._d;
         var changeddate1 = moment().subtract({ days: 5, months: 2 });
         document.getElementById("changeddate1").innerHTML = "Subtracting 5 days and 2 month using object method: " + changeddate1._d;
         var duration = moment.duration({ 'days': 10 });
         var changeddate2 = moment([2017, 10, 15]).subtract(duration);
         document.getElementById("changeddate2").innerHTML = "Subtracting 10 days from given date using duration method: " + changeddate2._d;
      </script>
   </body>
</html>

Advertisements
Loading...