Вопрос: Сколько выходных между двумя датами
Совет:
Date/Time: How many Sundays between two dates
--------------------------------------------------------------------------------
From an initial observation made by Lyle Fairfield, here a solution to getthe number of, let say, Wednesday, between two dates:
'************* Code Start *************
Public Function HowManyWD(FromDate As Date, _
ToDate As Date, _
WD As Long)
' No error handling actually supplied
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:
'************* Code Start *************
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
'************* Code End *************
код не мой автора не знаю, но возможно Евгений Серебряков
|