Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Work day count between two dates
Message
From
15/08/2002 06:36:38
Walter Meester
HoogkarspelNetherlands
 
 
To
14/08/2002 22:55:16
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00689838
Message ID:
00689895
Views:
31
Hi scot,

The following code should be faster than the code provided by Al, especially if the number of days between the two dates grow. Note that is does not matter if you pass the two dates in reverse order.
LPARAMETERS dDate1, dDate2
LOCAL nWorkDays

nWorkDays = INT(ABS(dDate1 - dDate2) / 7)* 5

FOR nT = 1 TO ABS(dDate1 - dDate2) % 7
	IF BETWEEN(DOW(MAX(dDate2,dDate1) +1 - nT),2,6)
		nworkDays = nWorkDays+1
	ENDIF
ENDFOR
RETURN nWorkDays
If you want to exclude holidays also you might want to enhance this routine in the following manner:
LPARAMETERS dDate1, dDate2
LOCAL nWorkDays, nHolidays

CALCULATE CNT() FOR BETWEEN(DOW(HolidayTable.Date),2,6) AND ;
    BETWEEN(HolidayTable.Date,MIN(dDate1,dDate2), MAX(dDate1,dDate2)) TO nHolidays IN HolidayTable

nWorkDays = INT(ABS(dDate1 - dDate2) / 7)* 5 - nHolidays

FOR nT = 1 TO ABS(dDate1 - dDate2) % 7
	IF BETWEEN(DOW(MAX(dDate2,dDate1) +1 - nT),2,6)
		nworkDays = nWorkDays+1
	ENDIF
ENDFOR
RETURN nWorkDays
>Hi all,
>
>I'm coding some project metrics using input from a MS Project ASCII export. Cosidering scheduling typically uses only work days (M-F), I need some help coding a routine which will count the number of work days (exlcuding Sat and Sun) between two dates. any assistance would be appreciated...
>
>Thanks,
>
>Scott Rands
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform