vb中什么函数能够获取到这个月的月底日期

2024-11-28 20:47:32
推荐回答(2个)
回答1:

你是要知道这个月最后一天是几号?
可以从下个月1号退一天:
a = DateAdd("d", -1, DateSerial(Year(Date), Month(Date) + 1, 1))
Date 这个是函数,返回当前日期,也可以指定日期,将Date换成其他日期值即可

回答2:

没有现成的,自己写一个:
Private Sub Command1_Click()
MsgBox DaysOfMonth(Year(Now), Month(Now))
End Sub
Function DaysOfMonth(Year As Long, Month As Long) As Long
Dim Day1 As String, Day2 As String
Day1 = CStr(Year) + "- " + CStr(Month) + "-1 "
Day2 = CStr(Year) + "- " + CStr(Month + 1) + "-1 "
DaysOfMonth = DateDiff("d", Day1, Day2)
End Function