Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Work days between two dates - finally!
Message
From
08/06/2003 08:05:59
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00797684
Message ID:
00797739
Views:
25
Thanks, here is a newer version which also is based upon weeks but in a different way.
LPARAMETERS dDate1, dDate2
LOCAL wks, wkd

hd = MAX(ddate1,ddate2)
ld = Min(ddate1,ddate2)

wks = INT( (hd - ld)/ 7)

* Return Weeks * 5 which is overal workdays
* Adjust for starting day of the first week
* And adjust for the last partial week

RETURN ;
    INT(wks * 5 + ;
    IIF(DOW(ld,2) < 6, 6-DOW(ld,2),0) + ;
    IIF(DOW(hd,2) < 6, DOW(hd,2),0) )
On my computer (AMD 1.6g 256mb) a 100,000 randomized test took 2.031 seconds including the considerable overhead of the test itself.
ld = RAND(-1)
nStart = SECONDS()
FOR i = 1 TO 100000
	noffset = INT(RAND()* 36)
	ld = GOMONTH(DATE(),1-noffset)
	hd = GOMONTH(DATE(),noffset)
	wkd = workdays(ld,hd)
ENDFOR
MESSAGEBOX('Execution time was '+TRANSFORM(SECONDS()-nstart)+' seconds')
What do you think of this version?

Thanks

Glenn


>Glenn,
>
>That code will fail if the dates cross a year boundary or are more than a year apart.
>
>>I needed a solution to determine the number of workdays between two dates and have not been satisfied with the prevalent techniques.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform