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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

# days between 2 dates - excluding weekends

Status
Not open for further replies.

psykoProgrammer

Programmer
Dec 15, 2004
16
CA
All,

I'm going to be a little bold and start thanking you ahead of time, because i'm certain someone out there knows how to do this fairly easily. :)

I'm a VB programmer, and as such can do this in that language, but am a newbie when it comes to VFP9; hence the reason i could use a hand.

Someone in my office was asking how you can take 2 dates and determine the number of days between them (i located an answer in the forum), but the request is to actually exclude weekends. I know i could use some function to test the day of the week and then determine if i should include the day in my total, but that sounds like it would be really slow.

Any other good solutions out there?

Thanks!
 
Solution by Sergey Karimov:

Code:
FUNCTION WorkDays(d1, d2)
* Returns the number of working days (Mondays - Fridays)
* in the date range d1 - d2.
*
* This function evolved from Mike Yearwood's function
* WEEKDAYS.PRG, see:
* [URL unfurl="true"]http://www.finn.wikis.com/wc.dll?Wiki~Weekdays~VFP[/URL]
* as well as from its modifications published on
* [URL unfurl="true"]www.universalthread.com.[/URL]
*
* Sergey Karimov

LOCAL nDays, nDow

nDays= ABS(d1-d2)+1
nDow= 7-DOW(MIN(d1,d2),2)

RETURN nDays - INT(nDays/7)*2 - SIGN(nDays%7-nDow) - SIGN(nDow)
 
Well thank you kindly!

That was fast, and i knew the solution had to be posted somewhere :p

I appreciate the effort; cheers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top