# 写个Function供各位参考！

Posted by SuBird on April 08, 1999 at 10:40:14:

In Reply to: 如何利用年月资料得知当月的总天数 posted by mosa on April 07, 1999 at 15:42:37:

: 请问如何利用取得的年与月的资料来判定当月的天数?

Re:
因为有闰年的问题(二月)，故需加以判断
Public Function DaysOfMonth(D As Date) As Long
Dim m As Long, y As Long
m = Month(D)
y = Year(D)
Select Case m
Case 1, 3, 5, 7, 8, 10, 12
DaysOfMonth = 31
Case 4, 6, 9, 11
DaysOfMonth = 30
Case 2
DaysOfMonth = IIf((y Mod 4 = 0 And y Mod 100 <> 0) Or (y Mod 400) = 0, 29, 28)
End Select
End Function

Follow Ups:

- 另一方法....DatePart() 与 DateAdd()函数 SuBird 10:53:27 4/08/99 (0)
- Re: 心得 show 一下 ! 安宝 10:52:27 4/08/99 (0)