Last Day of the Month

What the Function to find Last Date of the Month ?
thangaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Erick37Commented:
Here are a couple of functions found on the internet:

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
0
JuiletteCommented:
MsgBox Day(DateSerial(Year(Date), Month(Date) + 1, 0))
0
julianpointerCommented:
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
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Erick37Commented:
Will this work for all regional settings?
0
julianpointerCommented:
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
0
syleshCommented:
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
0
JuiletteCommented:
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?
0
thangaAuthor Commented:
Juilette u r correct. Thanks a lot
0
JuiletteCommented:
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
0
JuiletteCommented:
Answered in comments..Thanks
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.