MsgBox DateDiff("d", Date, DateAdd("m", -1, Date))

解决方案 »

  1.   

    Returns a Variant (Long) specifying the number of time intervals between two specified dates.SyntaxDateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
      

  2.   

    Dim Date1, Date2 As String
    Date1 = Year(DateAdd("m", -1, Now())) & "/" & Month(DateAdd("m", -1, Now())) & "/1"
    Date2 = Year(Now()) & "/" & Month(Now()) & "/1"
    MsgBox DateDiff("d", Date1, Date2)
      

  3.   

    不难,作几个select case,再判断一下是不是闰年。
    如果你的程序的运行有一定时间范围,比如只有20年,那索性就把这20年里的闰年列表出来就可以了。
    或者用这个函数Private Function getMonthDay(ByVal vDate As Date) As Long
    Dim newDate As Date
    newDate = DateAdd("m", 1, vDate) '先取下个月newDate = DateSerial(Year(newDate), Month(newDate), 1)  '获得下个月的1号
    newDate = newDate - 1           '再回到这个月最后一天getMonthDay = Day(newDate)      '返回
    End Function
      

  4.   

    MsgBox DateDiff("d", DateAdd("m", -1, Date), Date)