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 Diff 2

Status
Not open for further replies.

Kosmo2

Technical User
Mar 21, 2002
18
CA
This Maybe a common question but can anybody give me a line on working out the number of days between 2 work days in a query ?? That is between Monday to Friday on any given date, my fields are :- "Stop Date","Re-Start Date" and number of "Elapsed Days "



Thanks

Mick
 
Thanks Leigh, but does this takin into consideration weekends ??? I need a count of WORK DAYS only . . .



Thanks for the quick response though



Mick
 
thanks Les, that looks good , however its a little more complex than I envisioned , do you know if there is any quick and easy equation which I can simply use as an arguement within my query without creating new tables and complex things ???
 
Not that common, Mick...
Just look at my simple question - thread702-652802
"If it's Access, it ain't easy"

Just considering Monday through Friday being workdays and not considering holidays the following should get you there. Access considers Sunday as the first (1) day of the week and Saturday as the last (7).
I assume your date range starts with "stop date" and ends with "restart date" - minor adjustment if it's the other way around. And note there's no provision for invalid dates.

Dim n As Long
Dim nbrdays As Integer
Dim Elapsed_Days As Integer
Dim workdate As Date

(Add 1 for inclusive dates)
nbrdays = DateDiff("d", stopdate, restartdate) + 1

For n = 0 To nbrdays
workdate = DateAdd("d", n, stopdate)
If Weekday(workdate) not in (1, 7) Then
Elapsed_Days = Elapsed_Days + 1
End If
Next




HTH,
Bob
Thread181-473997 provides information regarding this site.
 
Thanks Bob , this looks interesting , I think it will suit me fine , YA I guess your right "If it's Access, it ain't easy" , I figured it was a common question and something simple which MS built into Access , I guess I was wrong :)


Thanks to everybody who gave a reply


Mick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top