[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Last Day of the Month

What the Function to find Last Date of the Month ?
0
thanga
Asked:
thanga
  • 4
  • 2
  • 2
  • +2
1 Solution
 
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now