急救!!关于日期的函数!怎么 知道 某年某月 的 最后一天 是多少号?

解决方案 »

  1.   

    下面是针对某月求出最后一天,你可以修改DateSerial()中的年,来实现对某年某月的天数返回 
    If IsNumeric(Text1.Text) And InStr(Text1.Text, ".") = 0 And InStr(Text1.Text, "-") = 0 Then
       If CLng(Text1.Text) > 0 And CLng(Text1.Text) <= 12 Then
          MsgBox DateDiff("d", DateSerial(Year(Now()), Text1.Text, 1), DateAdd("m", 1, DateSerial(Year(Now()), Text1.Text, 1)))
       Else
          MsgBox "Error"
       End If
    Else
       MsgBox "Error, Wrong Value"
    End If
      

  2.   

    查找月份的最后一天
     
     
    In many industries (particularly in the insurance industry), it注释:s important to know the last day of the month. To find the last day of a given month, add a text box and a command button to a form. Enter the following code in the command button:Dim TEMP2 As Date
    Dim nLastDay As Integer
    TEMP2 = InputBox$("Please Enter A Date", "LastDay")
    nLastDay = DatePart("d", DateAdd("M", 1, TEMP2 - DatePart("d", TEMP2)))
    Text1.Text = nLastDay
    When you run the application and click the button, you注释:ll be prompted for a date. Then, the program will display the last day of that month of any year.  
     
      
      

  3.   

    dim lastday as datetimelastday=dateadd("d",-1,dateadd("M",1,Cdate("" & year(date()) & "-" & month(date()) & "-1"))
      

  4.   

    ''''''功能:返回某一月的天数
    ''''''参数:任意的日期变量
    Public Function GetLastDay(ByVal valDate As Date) As Integer
        Dim dat1 As Date
        Dim i    As Integer
        i = Day(valDate) - 1       
        dat1 = DateAdd("d", -i, valDate)
        dat1 = DateAdd("m", 1, dat1)
        GetLastDay = Day(dat1 - 1) 
    End Function
      

  5.   

    问题太简单,利用两次减法求差:
    ---------------------------------
    算法思路如下:
    32-(dt+(32-dt.day)).day其中dt是当前日期变量。---例如,dt=20030410
    32-dt.day = 22
    dt+(32-dt.day)=20030410+22 = 20030502
    (dt+(32-dt.day)).day = 2
    32-(dt+(32-dt.day)).day = 32-2 = 30 (天)