Hello,
I have looked around trying to find a solution to the same old problem of trying to calculate how many Working Days are between two dates in a query, I found some code that works great except when one of the dates is blank, (Brings up a debug error!). This is really annoying me, is there any way around this? Module code used is as follows,
Any help would be greatly welcomed!
Simon
I have looked around trying to find a solution to the same old problem of trying to calculate how many Working Days are between two dates in a query, I found some code that works great except when one of the dates is blank, (Brings up a debug error!). This is really annoying me, is there any way around this? Module code used is as follows,
Code:
Function DateDiffW(BegDate, EndDate)
Const SUNDAY = 1
Const SATURDAY = 7
Dim NumWeeks As Integer
If BegDate > EndDate Then
DateDiffW = 0
Else
Select Case Weekday(BegDate)
Case SUNDAY: BegDate = BegDate + 1
Case SATURDAY: BegDate = BegDate + 2
End Select
Select Case Weekday(EndDate)
Case SUNDAY: EndDate = EndDate - 2
Case SATURDAY: EndDate = EndDate - 1
End Select
NumWeeks = DateDiff("ww", BegDate, EndDate)
DateDiffW = NumWeeks * 5 + Weekday(EndDate) - Weekday(BegDate)
End If
End Function
Any help would be greatly welcomed!
Simon