Private Sub Command1_Click()
MsgBox GetDayNum(Text1.Text)
End SubPrivate Function GetDayNum(sDate As Variant)
Select Case Val(DatePart("M", sDate))
Case 1, 3, 5, 7, 8, 10, 12
GetDayNum = 31
Case 4, 6, 9, 11
GetDayNum = 30
Case 2
If IsDate(DatePart("yyyy", sDate) & "-2-29") Then
GetDayNum = 29
Else
GetDayNum = 28
End If
End Select
End Function
MsgBox GetDayNum(Text1.Text)
End SubPrivate Function GetDayNum(sDate As Variant)
Select Case Val(DatePart("M", sDate))
Case 1, 3, 5, 7, 8, 10, 12
GetDayNum = 31
Case 4, 6, 9, 11
GetDayNum = 30
Case 2
If IsDate(DatePart("yyyy", sDate) & "-2-29") Then
GetDayNum = 29
Else
GetDayNum = 28
End If
End Select
End Function
? Datediff("d","2002-07-01","2002-08-01")
date2为下个月的1号,如#2002-3-1#执行函数后,值为28简单实用灵活
Msgbox CDate("2002-7-1") - CDate("2002-6-1")