求教计算任何一个月的天数的算法:
参数:某年某月(2004-07-01),结果:这个月有多少天

解决方案 »

  1.   

    '取出当年当月的最后一天,也就是当年当月有多少天
    Public Function GetLastDay(ByVal intYear As Integer, ByVal intMonth As Integer) As Integer
        Select Case intMonth
            '2月
            Case 2
                If (((intYear Mod 4) = 0 And (intYear Mod 100) <> 0) Or ((intYear Mod 400) = 0)) Then
                    GetLastDay = 29
                Else
                    GetLastDay = 28
                End If
            '大月
            Case 1, 3, 5, 7, 8, 10, 12
                GetLastDay = 31
            '小月
            Case 4, 6, 9, 11
                GetLastDay = 30
        End Select
    End Function
      

  2.   

    http://community.csdn.net/Expert/topic/3035/3035384.xml?temp=.7663538
      

  3.   

    Function MaxDay(ByVal y As Integer, m As Integer) As Integer
        '其中 y 是年份,m 是月份
        MaxDay = Day(DateSerial(y, m + 1, 0))
    End Function