# Thread: How to find the last day of the month?

1. Registered User
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,?????)

2. Stuck on my opinions...
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```

.

3. Registered User
Join Date
Nov 2004
Location
Norway
Posts
441
DateSerial(ye,mon+1,0)

4. Registered User
Join Date
Nov 2002
Posts
272
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
•