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

Urgent date problem 1

Status
Not open for further replies.

EKC

Technical User
Jan 13, 2001
43
0
0
CA
Hello everyone,

I have two dates:start date of job(jstart) and end date of job(jend).I need to calculate time needed to finish the job,so I have (jend-jstart).That gives me time in days which is OK but that also include weekends which should't be.So my question is how to eliminate Saturdays and Sundays from this day count?
Any help appreciated and any idea welcomed,
Lyn
 
I guess you could write a procedure that tells you how many 'working' days there are in a month using functions like DOW(). And then summing up all the days not being sunday and saturday.

HTH,

Weedz (Wietze Veld)
veld4663@exact.nl
The Netherlands

They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best.

After the GoldRush - Steve McConnell
 
Since dow() returns a number, and since you're presumably only going to have the start and end days be on a work day, you could simply take the integer value of (jend-jstart)/7 times 5 and add back dow(jend)- dow(jstart)+1 if jend > jstart or 7-(dow(jend)- dow(jstart)+1) if jend < jstart. Please check my logic, I haven't tried it out; but the principle will work. Of course you still need to allow for holidays if any. --Dave
 
Hi Lyn,

Another way:

FUNCTION weekdays
LPARAMETERS begdate, enddate
j = 0
datex = begdate

DO WHILE datex <= enddate
IF DOW(datex) != 1 AND DOW(datex) != 7
j = j + 1
ENDIF
datex = datex + 1
ENDDO

RETURN j


Jim
 
Also check out this thread for other ways of doing it.
thread184-36696 Date Difference not including weekends. David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top