How to Handle Feb 28 and 29?

M

MJ

I have a database that triggers a table archive piece when the end of the
month occurs. In the case of a leap year, I think that in the case of
February the way it is currently written the actions are done on both Feb 28
and 29:

If ((Format(date, "dd") = "28") And (Format(date, "mmm") = "Feb")) Or _
((Format(date, "dd") = "29") And (Format(date, "mmm") = "Feb")) Then


Is there a way that I can check to see if this is a leap year or not, then
do the appropriate check for 28 or 29?
 
D

Douglas J. Steele

Here's a function that will tell you whether a given year's a leap year or
not:

Function IsLeapYear(YearNumber As Long) As Boolean

IsLeapYear = Day(DateSerial(YearNumber, 2, 29)) = 29

End Function

Alternatively, here's a function that will give you the last day of the
month:

Function LastDayOfMonth(YearNumber As Long, MonthNumber As Long) As Long

LastDayOfMonth = Day(YearNumber, MonthNumber + 1, 0))

End Function
 
J

John W. Vinson

I have a database that triggers a table archive piece when the end of the
month occurs. In the case of a leap year, I think that in the case of
February the way it is currently written the actions are done on both Feb 28
and 29:

If ((Format(date, "dd") = "28") And (Format(date, "mmm") = "Feb")) Or _
((Format(date, "dd") = "29") And (Format(date, "mmm") = "Feb")) Then


Is there a way that I can check to see if this is a leap year or not, then
do the appropriate check for 28 or 29?

That's an awfully complicated way to find the last day of the month! This
expression will work to find the last day of any month in any year:

DateSerial(Year(Date()), Month(Date()) + 1, 0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top