From an initial observation made by Lyle Fairfield, here a solution
to get the number of, let's say, Wednesday, between two dates:
Public Function HowManyWD(FromDate As Date, _
ToDate As Date, _
WD As Long)
HowManyWD = DateDiff("ww", FromDate, ToDate, WD) _
- Int(WD = WeekDay(FromDate))
End Function
'************* Code End *************
In the same way, someone can easily get the number of weekdays
(excluding weekends) by subtracting number of Sundays and Saturdays:
Public Function HowManyWeekDay(FromDate As Date, _
ToDate As Date, _
Optional ToDateIsIncluded As Boolean = True)
HowManyWeekDay = DateDiff("d", FromDate, ToDate) - _
ToDateIsIncluded - _
HowManyWD(FromDate, ToDate, vbSunday) - _
HowManyWD(FromDate, ToDate, vbSaturday)
End Function
|