thanga
asked on
Last Day of the Month
What the Function to find Last Date of the Month ?
MsgBox Day(DateSerial(Year(Date), Month(Date) + 1, 0))
try this...
Public Function lastday(sMonth As String) As Date
Dim sDate As String
sDate = "1/" & sMonth & "/" & DatePart("yyyy", Now())
lastday = DateAdd("d", -1, DateAdd("m", 1, sDate))
MsgBox lastday
End Function
Public Function lastday(sMonth As String) As Date
Dim sDate As String
sDate = "1/" & sMonth & "/" & DatePart("yyyy", Now())
lastday = DateAdd("d", -1, DateAdd("m", 1, sDate))
MsgBox lastday
End Function
Will this work for all regional settings?
NO....
This will though.
Public Function lastday(sMonth As String) As Date
' sMonth = "Jan","Feb" ...
Dim sDate As String
sDate = sMonth & " 1 " & DatePart("yyyy", Now())
lastday = DateAdd("d", -1, DateAdd("m", 1, sDate))
End Function
This will though.
Public Function lastday(sMonth As String) As Date
' sMonth = "Jan","Feb" ...
Dim sDate As String
sDate = sMonth & " 1 " & DatePart("yyyy", Now())
lastday = DateAdd("d", -1, DateAdd("m", 1, sDate))
End Function
Finding the last day of the month
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
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
Why all the code when vb has the built in function:[ 1 line of code ]
Day(DateSerial(Year(Date), Month(Date) + 1, 0))
In help there are other versions as well
Am I missing something?
Day(DateSerial(Year(Date),
In help there are other versions as well
Am I missing something?
ASKER
Juilette u r correct. Thanks a lot
OK Thanga..reject julianpointer's proposed answer and accept my comment as an answer...If you have problems doing so, just reject the proposed answer and I will submit my code as an answer.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Public Function FindEOM(ByVal dDate As Date) As String
Dim sNextMonth As Date
Dim sEndOfMonth As Date
sNextMonth = DateAdd("m", 1, dDate)
sEndOfMonth = sNextMonth - DatePart("d", sNextMonth)
FindEOM = Day(sEndOfMonth) 'Remove the Day() function to
'return the actual date.
End Function
Public Function LastDay(dDate As Date) As Integer
Dim i As Integer
Dim d As Date
For i = 31 To 28 Step -1
If IsDate(Month(dDate) & "/" & Trim(Str(i)) & _
"/" & Year(dDate)) Then
LastDay = i
Exit Function
End If
Next
End Function