Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Difference Not Including Weekends 3

Status
Not open for further replies.

logout151

IS-IT--Management
Nov 15, 2000
24
US
I need to calculate the difference of two dates, not including Sat. and Sun. Is there a formula that I can use for this? or what is the best way to solve this problem?

-Log
 
Unless you make some assumptions like subtracting 2 days for every 7, I can't see how you can do it without a brute-force loop.

Robert Bradley

 
FUNCTION DateDiff
lparameters dStart,dEnd,lExcludeWE

LOCAL lnCount,lnDays

lnCount=0
lnDays=dEnd-dStart
IF lExcludeWE
FOR X = 1 TO lnDays
IF DOW((dStart + X),2) <= 5
lnCount=1+lnCount
ENDIF
ENDFOR
ELSE
lnCount=lnDays
ENDIF

RETURN lnCount Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Or If You Like Do While Loops
*
[tt]
*procedure WeekDays
lparameter pdStart, pdEnding
lnDays = pdEnding - pdStart
do while pdStart < pdEnding
pdStart=pdStart+1
if between(dow(pdStart),2,6)
lnDays=lnDays+1
endif
enddo
return lnDays
[/tt]

David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
I found a VB function in the access forum that does this. It is not pretty but it does also handle holidays. I rewrote it (w/ authors permission) in VFP and posted as an FAQ. It does more than you need, but it is pretty neat none the less.

Pete
blindpete@mail.com

What your mother told you is true! You will go blind! (from moonshine anyway)
 
Cool David!

I'd give you a star but someone beat me to it :)

I read your functions. The philosophy is slightly different from the one I re-coded. The VB one interates the floating holidays. For instance Thanksgiving it counts the 4th Thurs in Nov. I am no calander guro... I have no idea how these things are actually defined. It would seem to me that both methods are likely required for a bolier plate function.

Pete
blindpete@mail.com

What your mother told you is true! You will go blind! (from moonshine anyway)
 
Great Responses for all of you! It ends up that I needed to exclude Holidays! Thanks for all your help

Logout
 
logout151, Pete,
I got bored at work yesterday and figured it was not fair to the other users of this forum that we just posted U.S. holidays, So I rewrote the program to use a database for mulit-country use. Go check it out now.
David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
David!

Your really racking up the stars!!!!!!!

Perhaps you will win for the week!



Pete
blindpete@mail.com

What your mother told you is true! You will go blind! (from moonshine anyway)
 
Now I'll have to put my head in a Vice to stop the swelling after your kind words. Tks Pete. David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
For future reference, here's a recent addition to the KB that addresses this topic.

Visual FoxPro 6.0 Sample: Calculates the Number of Business Days and Excludes Holidays/Weekends

Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top