p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript (http://p2p.wrox.com/forumdisplay.php?f=85)
-   -   How to calculate the work days beetwen two dates. (http://p2p.wrox.com/showthread.php?t=19128)

andres_pm September 28th, 2004 11:41 PM

How to calculate the work days beetwen two dates.
 
Hi,

I need to calculate the difference beetwen two dates, without the weekend (Saturday and Sunday) to display only the "Work" days.

For example:

Date 1: 29/09/2004
Date 2: 05/10/2004
Work days: 5 days

Anybody knows how to do this?

Thanks.


Santhi October 7th, 2004 06:23 AM

Here is the code...

function DayCount()
{
   var d1 = new Date(2004,09,29);
   var d2 = new Date(2004,10,05);
   var flag=true;
   var day,daycount=0;
   while(flag)
   {
      day=d1.getDay();
      if(day != 0 && day != 6)
         daycount++;
      d1.setDate(d1.getDate()+1) ;
      if(d1.getDate() == d2.getDate() &&
                  d1.getMonth()== d2.getMonth())
      {
          flag=false;
      }
 }
document.write("Work Day COunt"+daycount);
}



All times are GMT -4. The time now is 07:11 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.