title: Getting number of working days with javascript and jQuery UI datepicker
body: <p>I have two datepicker from which I can calculate the number of day without counting Saturday and Sunday. But I want to do this for Friday and Saturday. I have tried some different ways but failed. It was easy for me to handle number of day excluding Saturday and Sunday but not  for Friday and Saturday Following is my javascript code -</p>
  
  <pre><code>$(function() {
      $( "#startDate" ).datepicker({
          onSelect: calculateDays});
      });
  
      $(function() {
          $( "#endDate" ).datepicker({
              onSelect: calculateDays});
          });
  
          function calculateDays(startDate, endDate) {
              var form = this.form
  
              var startDate = document.getElementById("startDate").value;
              var startDate = new Date(startDate);
  
              var endDate = document.getElementById("endDate").value;
              var endDate = new Date(endDate);
  
              startDate.setHours(0,0,0,1); // Start just after midnight
              endDate.setHours(23,59,59,999); // End just before midnight
  
              var oneDay = 24*60*60*1000;
              var diff = endDate - startDate; // Milliseconds between datetime objects
              var days = Math.ceil(diff / oneDay);
  
              var weeks = Math.floor(days / 7);
              var days = days - (weeks * 2);
  
              // Handle special cases
              var startDay = startDate.getDay();
              var endDay = endDate.getDay();
  
              // Remove weekend not previously removed.
              if (startDay - endDay &gt; 1)
                  days = days - 2;
  
              // Remove start day if span starts on Sunday but ends before Saturday
              if (startDay == 0 &amp;&amp; endDay != 6)
                  days = days - 1
  
              // Remove end day if span ends on Saturday but starts after Sunday
              if (endDay == 6 &amp;&amp; startDay != 0)
                  days = days - 1
  
              if (days)
                  document.getElementById("result").innerHTML=days;
          }
  </code></pre>
  
  <p>And my HTML is:</p>
  
  <pre><code>&lt;form id="dateDifference" style="width:200px;"&gt;
      &lt;input name="startDate" id="startDate" value="" &gt;
      &lt;input name="endDate" id="endDate" value="" &gt;
  &lt;/form&gt;
  &lt;span id="result"&gt;&lt;/span&gt;
  </code></pre>