//给你一个思路! 如果月份是奇数且不是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
dim dDate as dateif month(dDate)=month(DATEADD("D",1,dDate)) then not last day else last day endif
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
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
最简单的函数 Function IsLastDay(dDate As Date) As Boolean IsLastDay = Month(dDate) - Month(DateAdd("D", 1, dDate)) End Function
如果月份是奇数且不是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
not last day
else
last day
endif
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
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
Function IsLastDay(dDate As Date) As Boolean
IsLastDay = Month(dDate) - Month(DateAdd("D", 1, dDate))
End Function
rainstormmaster(暴风雨 v2.0) 的程序很厉害
weiweiplay(虚幻) 的是正常思路
oho1937(压舟熊疯) 判断是不是最后一天
DTWUJP(建平.net) 的程序也很有创意
NewDate = DateAdd("d", -1, CDate(Year(Date) & "-" & Month(Date)+1 & "-01"))