Solved

Formula to find the last day of the month

Posted on 2000-04-10
6
169 Views
Last Modified: 2010-05-02
I need to find the last day of the current month (it could be any month).
0
Comment
Question by:rashida
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 4

Expert Comment

by:arcusd
ID: 2702694
Function MonthLastDay(mdate As Variant) As Variant
    On Error Resume Next
    Dim thismo, nextmo, thisyr, nextyr As Integer
    Dim mstr As String
    thismo = Month(mdate)
    thisyr = Year(mdate)
    If thismo = 12 Then
        nextmo = 1
        nextyr = thisyr + 1
    Else
        nextmo = thismo + 1
        nextyr = thisyr
    End If
    mstr = Trim(Str(nextmo)) + "/01/" + Trim(Str(nextyr))
    MonthLastDay = DateAdd("d", -1, CDate(mstr))
End Function


to call:

x = MonthLastDay(#12/01/1999#)
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2702697
Dim dDate As Date
dDate = #2/2/00#
Debug.Print Day(DateSerial(Year(dDate), Month(dDate) + 1, 0))
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2702771
For current month:

Debug.Print Day(DateSerial(Year(Date), Month(Date) + 1, 0))
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 25 total points
ID: 2703232
To find the LAST day of the current month, use this:
DateAdd("d", -1, DateAdd("m", 1, DateSerial(Year(Now), Month(Now), 1)))
(you may replace Now by the date you want)
0
 
LVL 1

Expert Comment

by:jannea
ID: 2703596
Function LastDay(ByVal XDate As Variant) As Variant
    If Not IsDate(XDate) Then MsgBox "Error", 16: Exit Function
    XDate = Format$(XDate, "yyyy-mm-dd")
    XDate = Left$(XDate, 8) & "01"
    XDate = DateAdd("d", -1, XDate)
    LastDay = DateAdd("m", 1, XDate)
End Function
0
 

Author Comment

by:rashida
ID: 2703768
This was the easiest of all.

Thanks!!
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question