Public Function DaysInMonth(byval MonthNo as int, optional byval YearNo as int = 0) as int
dim D as Date
' Use current year if nothing is specified
if YearNo = 0 then YearNo = Year()
' Construct date next to month specified
D = CDate(cstr(YearNo) & "-" & cstr((MonthNo mod 12) + 1) & "-01")
' Substract 1 day and take a day value
DaysInMonth = Day(dateadd(dd, -1, D))
end function
DaysInMonth = Day(DateAdd("d", -1, Ds))
Чудик писал(а):Подбправил в строке
- Код: Выделить всё
DaysInMonth = Day(DateAdd("d", -1, Ds))
В остальном все прекрасно. Работает. Спасибо.
DaysInMonth = Day(Ds-1)
Public Function DaysInMonth(ByVal MonthNo As Integer, Optional ByVal YearNo As Integer = 0) As Integer
' Use current year if nothing is specified
If YearNo = 0 Then YearNo = Year(Date)
' Construct date next to month specified
DaysInMonth = Day(DateAdd("m", 1, DateSerial(YearNo, MonthNo, 1) - 1))
End Function
Public Function DaysInMonth(dTemp As Date) As Integer
'Подсчитывает количество дней в месяце
DaysInMonth = DateSerial(Year(dTemp), Month(dTemp) + 1, Day(dTemp)) - DateSerial(Year(dTemp), Month(dTemp), Day(dTemp))
End Function
Public Function DaysInMonth(ByVal MonthNo As Integer, Optional ByVal YearNo As Integer = 0) As Integer
' Use current year if nothing is specified
If YearNo = 0 Then YearNo = Year(Date)
DaysInMonth = Choose(MonthNo, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
If (MonthNo = 2) And (YearNo Mod 4 = 0) And ((YearNo Mod 100 <> 0) Or (YearNo Mod 400 = 0)) Then DaysInMonth = DaysInMonth + 1
End Function
If (MonthNo = 2) And (YearNo Mod 4 = 0) And ((YearNo Mod 100 <> 0) Or (YearNo Mod 400 = 0)) Then DaysInMonth = DaysInMonth + 1
Сейчас этот форум просматривают: SemrushBot, Yandex-бот и гости: 96