Private Function GetLastDate(ByVal strDate As String) As String
Dim intYear As Integer
Dim intMonth As Integer
Dim strT As String
Dim I As Integer
intYear = Year(strDate)
intMonth = Month(strDate)
For I = 31 To 28 Step -1
strT = intYear & "-" & intMonth & "-" & I
If IsDate(strT) = True Then
GetLastDate = strT
Exit Function
End If
Next
End Function
Private Function GetLastDate(ByVal strDate As String) As String
Dim intYear As Integer
Dim intMonth As Integer
Dim strT As String
intYear = Year(strDate)
intMonth = Month(strDate)
strT = intYear & "-" & intMonth & "-31"
If IsDate(strT) = True Then
GetLastDate = strT
Exit Function
Else
strT = intYear & "-" & intMonth & "-30"
If IsDate(strT) = True Then
GetLastDate = strT
Exit Function
Else
strT = intYear & "-" & intMonth & "-29"
If IsDate(strT) = True Then
GetLastDate = strT
Exit Function
Else
strT = intYear & "-" & intMonth & "-28"
If IsDate(strT) = True Then
GetLastDate = strT
Exit Function
End If
End If
End If
End If
End Function
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")
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.
Private Function getlastday(ByVal mdate As Date) As Integer
Dim y As Integer, m As Integer
y = Year(mdate)
m = Month(mdate)
Dim d As Date
d = DateSerial(y, m + 1, 1)
d = DateAdd("d", -1, d)
getlastday = Day(d)
End Function
Private Sub Command2_Click()
'调用
MsgBox "当月最后一天的日期为:" + CStr(getlastday(CDate("2004年1月5日")))
End Sub
Function lastday(ByVal mydate As Date) As Date
lastday = DateSerial(Year(mydate), Month(mydate) + 1, 0)
End Function
Private Sub Form_Load()
MsgBox lastday(#1/5/2004#)
End Sub