Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    313

    Unanswered: How to find the last day of the month?

    Hi:

    MS Access:

    How to find the last day of the month?

    ye = Year // input variable
    mon = month // input variable

    DateSerial(ye,mon,1) // this is first day of the month.

    What function can be found the last day, because every month has different number , 28, 31,etc.

    DateSerial(ye,mon,?????)
    Please let me know, thanks.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    You can use this function to find the last day of a given month:

    Code:
    Private Function LastDayofMonth(TheDate As Date) As Integer
       Dim intMonth As Integer, intYear As Integer
       intMonth = Month(TheDate) Mod 12 + 1
       intYear = Year(TheDate)
       LastDayofMonth = Format(DateSerial(intYear, intMonth, 1) - 1, "dd")
    End Function

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    DateSerial(ye,mon+1,0)
    Roy-Vidar

  4. #4
    Join Date
    Nov 2002
    Posts
    272
    Quote Originally Posted by CyberLynx
    You can use this function to find the last day of a given month:

    Code:
    Private Function LastDayofMonth(TheDate As Date) As Integer
       Dim intMonth As Integer, intYear As Integer
       intMonth = Month(TheDate) Mod 12 + 1
       intYear = Year(TheDate)
       LastDayofMonth = Format(DateSerial(intYear, intMonth, 1) - 1, "dd")
    End Function
    .
    Shouldn't that be
    (Month(TheDate) + 1) Mod 12
    ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •