JOM,
I've struggled with this before. Weekends (and holidays) always need to
be excluded when I do date calculations.
My basic solution is to add a public function in a module to do the
work... then, it's a matter of accumulating weekdays between the two
dates. As an example (Access 2000):
Public Function BizDayDiff(lhs as Date, rhs as Date) As Integer
' lhs = Left Hand Side and rhs = Right Hand Side
' as in "lhs - rhs"
' Left Hand Side should always be the greater date
' you can test and swap if you want to.
BizDayDiff = 0
Dim bookmark As Date:
bookmark = lhs
Dim w As Integer:
w = 0
Do While (bookmark < rhs)
' increment the counter
bookmark = DateAdd("d", 1, bookmark)
' increment the count on non-weekends ("W" returns day of week 1-7)
w = DatePart("W", bookmark)
If w <> 1 And w <> 7 Then BizDayDiff = BizDayDiff + 1
Loop
End Function
I think this should work ok. Keep in mind that, the loop runs n times
where n is the actual number of days between two dates. This means that
it scales pretty horribly if your distance between dates is large in
general.
Just set your query to this function with the two dates you want - diff:
BizDayDiff([date1], [date2]) where date1 needs to be larger than date 2
or it will output 0.
There may be a more efficient way to do this, but this should work
Good luck,
Luke
I have a query that am trying to subtract 2 dates excluding weekeds
who do I do that in a query... I have datediff('d',date,datecompleted)
Please help!