title: How to convert the selected date to last month and last year date using moment.js?
body: <p>I'm working on moment.js and I confused to convert the two dates. </p>
  
  <pre><code>For Example:
  
      var start = moment().startOf('month');  // Dec 01 2017
      var end = moment(); // Dec 31 2017
  </code></pre>
  
  <p>I would like to convert this date to last month and last year.</p>
  
  <pre><code>Eg: 
      Last Month: Nov 01 2017 &amp; Nov 30 2017 (Problem in converting 31 to 30)
      Last Year: Dec 01 2016 &amp; Dec 31 2016
  </code></pre>
  
  <p>If I change the start and end date another value need to change.</p>
  
  <p><strong>Updated:</strong></p>
  
  <pre><code>$(function() {
  
      var start = moment().startOf('month'); // eg: 12/01/2017
      var end = moment();  // eg: 12/31/2017
  
      function cb(start, end) {
  
          var startyear = moment().subtract(start, 'year'); // eg: 12/01/2016
          var endyear = moment().subtract(end, 'year'); // eg: 12/31/2016
  
          var startmonth = moment().subtract(start, 'month'); // eg: 11/01/2017
          var endmonth = moment().subtract(end, 'month'); // eg: 11/30/2017
  
          $('#reportrange span').html(start.format('MMM D, YYYY') + ' - ' + end.format('MMM D, YYYY'));
          $('#report1 span').html(startyear.format('MMM D, YYYY') + ' - ' + endyear.format('MMM D, YYYY'));
          $('#report2 span').html(startmonth.format('MMM D, YYYY') + ' - ' + endmonth.format('MMM D, YYYY'));
      }
  
       $('#reportrange').daterangepicker({
           "autoApply": true,
          "showDropdowns": false,
          "alwaysShowCalendars": false,
          "opens": "left",
          startDate: start,
          endDate: end,
      },cb);  
  
      cb(start, end);
      });
  </code></pre>
  
  <p>If I select two dates, I want to convert those dates to year and month. </p>