title: Getting Working Days Using Javascript
body: <p>I'm trying to get the working days between two date.
  Example: stdate = 28/10/2011 and endate = 04/11/2011. This should be 6 working days, but its only giving 5 days.</p>
  
  <pre><code>var workingdays = 0;
  var weekday     = new Array(7);
  weekday[0]="Sunday";
  weekday[1]="Monday";
  weekday[2]="Tuesday";
  weekday[3]="Wednesday";
  weekday[4]="Thursday";
  weekday[5]="Friday";
  weekday[6]="Saturday";
  
  while (stdate &lt;= endate) 
  {
      var day = weekday[stdate.getDay()];
      if(day != "Saturday" &amp;&amp; day != "Sunday") 
      {
          workingdays++; 
      }
      console.log(weekday[stdate.getDay()]);
      stdate = new Date(stdate.getTime() + 86400000); 
  }
  </code></pre>
  
  <p>The console log shows the results below.</p>
  
  <pre><code>Friday
  Saturday
  Sunday
  Sunday
  Monday
  Tuesday
  Wednesday
  Thursday
  </code></pre>
  
  <p>Sunday shows twice for some reason. Any help would be appreciated.</p>