title: jquery datepicker - calculate date difference
body: <p>I'm new at this and I really need your help because I've been struggling for days with this…
  I want to calculate days between two dates chosen with datepicker. Am I on the right track with this or am I doing this completely wrong? All I know is that when I click on Number of days, it doesn't show anything. Here is my code</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;head&gt;
      &lt;link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/&gt;
        &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"&gt;&lt;/script&gt;
        &lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"&gt;&lt;/script&gt;
        &lt;script&gt;
          $(document).ready(function () {
  
              $("#datepicker").datepicker({ minDate: "01/07/2012", maxDate: "01/30/2012" });
  
              $("#datepicker1").datepicker({ beforeShow: setminDate });
  
              var start1 = $('#datepicker');      
              function setminDate() {          
                  var p = start1.datepicker('getDate');          
                  if (p) { 
                      var k ="01/30/2012";            
                      return {
                      minDate: p,
                      maxDate:k
                  }};         
              }           
              function clearEndDate(dateText, inst) {          
                  end1.val('');      
              }  
          });
      $(function() {
          $( "#datepicker1" ).datepicker({ dateFormat: 'mm/dd/yyyy' });
          $( "#datepicker" ).datepicker({ dateFormat: 'mm/dd/yyyy' });
      });
      $('button').click(function() {
          var start = $('#datepicker1').datepicker('getDate');
          var end   = $('#datepicker').datepicker('getDate');
          var days   = (end - start)/1000/60/60/24;
          alert(days);
      });
      &lt;/script&gt;
      &lt;body&gt;
      &lt;form&gt;
          from: 
          &lt;input id="datepicker" readonly='true'/&gt;&lt;br&gt;
          to: 
          &lt;input id="datepicker1" readonly='true'/&gt;&lt;br&gt;
      &lt;/form&gt;
          &lt;br&gt;&lt;button&gt;number of days&lt;/button&gt;
  
      &lt;/body&gt; 
      &lt;/html&gt;
  </code></pre>