如何判断某个日期当月的最后一天
比如"2005-12-1"的最后一天是"2005-12-31"
有没有判断某个日期当月最后一天的函数?
或者其它方法也行

解决方案 »

  1.   

    http://community.csdn.net/Expert/topic/4414/4414979.xml?temp=8.791751E-02
      

  2.   

    //给你一个思路!
    如果月份是奇数且不是7,最后一天直接就是30,如果是偶数和7 且不是2,最后一天直接就是31
    其他的话,就判断是否是闰年,是闰年29天,不是闰年是28天,你把条件组合就对了是一种思路,不过这样就太麻烦了,其实当月最后一天就是下个月第一天的前一天,你取得下个月的第一天直接-1就可以了,也就是下个月的第0天:Private Sub Command1_Click()
    Dim a As Date
    a = Now
    MsgBox monthlastday(a)
    End Sub
    Private Function monthlastday(ByVal mdate As Date) As Date
        monthlastday = DateSerial(Year(mdate), Month(mdate) + 1, 0)
    End Function
      

  3.   

    dim dDate as dateif month(dDate)=month(DATEADD("D",1,dDate)) then
        not last day
    else
        last day
    endif
      

  4.   

    Public Function GetDays(ByVal DTM As Date) As Long
        Dim lYear As Long, lMonth As Long
        lYear = Year(DTM)
        lMonth = Month(DTM)
        
        Select Case lMonth
            Case 1, 3, 5, 7, 8, 10, 12
                GetDays = 31
            Case 2
                If (lYear Mod 4) = 0 Then
                    GetDays = 29
                Else
                    GetDays = 28
                End If
            Case 4, 6, 9, 11
                GetDays = 30
        End Select
    End Function
      

  5.   

    Public Function GetLastOfMonthDate(ByVal TheDate As Date) As Date
        Dim NewDate As Date
        Dim TheYear As String
        Dim TheMonth As String    NewDate = DateAdd("m", 1, TheDate)    '先将原来时间增加一个月
        TheYear = Year(NewDate)
        TheMonth = month(NewDate)    '得到那个月最后一天的日期
        NewDate = DateAdd("d", -1, CDate(TheYear & "-" & TheMonth & "-01"))
        GetLastOfMonthDate = NewDate
    End Function
      

  6.   

    最简单的函数
    Function IsLastDay(dDate As Date) As Boolean
    IsLastDay = Month(dDate) - Month(DateAdd("D", 1, dDate))
    End Function
      

  7.   

    zfl2k(风) 的有问题,当前日期加一天后还是同一个月
     rainstormmaster(暴风雨 v2.0) 的程序很厉害
    weiweiplay(虚幻) 的是正常思路
     oho1937(压舟熊疯) 判断是不是最后一天
     DTWUJP(建平.net) 的程序也很有创意
      

  8.   

    也可以得到下个月的第一天,再减去一天,就是当月的最后一天了。
    NewDate = DateAdd("d", -1, CDate(Year(Date) & "-" & Month(Date)+1 & "-01"))