title: How to calculate number of days and date range in jQuery Datepicker?
body: <p>I am using jQuery Datepicker. I am able to calculate the number of days between two date selected but I need to be able to select a date range(selected 'fromdate' to become 'minim' for 'todate' and selected 'todate' to become 'maxim' for 'fromdate').
  I am using this code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function () { 
  var selector = function (dateStr) {
          var d1 = $('.fromdate').datepicker('getDate');
          var d2 = $('.todate').datepicker('getDate');
          var diff = 1;
          if (d1 &amp;&amp; d2) {
              diff = diff + Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
          }
          $('.calculated').val(diff);
          $('.minim').val(d1)
      }
  $('.fromdate').datepicker({
                  dateFormat : 'yy-mm-dd',
                  changeMonth: true,
                  changeYear: true,
                  minDate: 'minim'
  });
  $('.todate').datepicker({ 
                  dateFormat : 'yy-mm-dd',
                  changeMonth: true,
                  changeYear: true,
                  minDate: 'fromdate'
  });
  $('.fromdate,.todate').change(selector)
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Thank you!</p>