title: How to calculate difference of between two bootstrap datepicker?
body: <p>Hi i have two bootstrap datepickers and i want to calculate the difference between the dates and show the number of days in a input box. Code:-</p>
  
  <pre><code>&lt;input class="form-control datepicker" type="text" id="fdate" name="fdate"&gt;
  &lt;input class="form-control datepicker" type="text" id="tdate" name="tdate"&gt;
  &lt;input class="form-control" type="text" name="days" id="days"&gt;
  </code></pre>
  
  <p>JavaScript:- </p>
  
  <pre><code>&lt;script&gt;
  $(function() {
  
  $('#fdate').datepicker({
      format: "dd-M-yy",
      todayHighlight:'TRUE',
      autoclose: true,
      minDate: 0,
      maxDate: '+1Y+6M',
      onSelect: function (dateStr) {
          var min = $(this).datepicker('getDate'); 
          $("#tdate").datepicker('option', 'minDate', min || '0');
      }
  }); 
  
  $('#tdate').datepicker({
      format: "dd-M-yy",
      todayHighlight:'TRUE',
      autoclose: true,
      minDate: '0',
      maxDate: '+1Y+6M',
      onSelect: function (dateStr) {
          var max = $(this).datepicker('getDate'); 
          $('#datepicker').datepicker('option', 'maxDate', max || '+1Y+6M');
          var start = $("#fdate").datepicker("getDate");
          var end = $("#tdate").datepicker("getDate");
          var days = (end - start) / (1000 * 60 * 60 * 24);
          $("#days").val(days);
      }
  }); 
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>I have tried the above javascript to do it but it doesn't work. I am not sure whether it is the right way or not. Please help me in pointing out what is going wrong or if there is a better way of doing it. ANy help is highly appreciated.</p>