Code to calculate a leap year

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anybody know of any code to calculate whether a certain year is a leap
year, in Access VBA?
 
Does anybody know of any code to calculate whether a certain year is a leap
year, in Access VBA?

Check for whether 2/29/xxxx is a date:
In the debug window
? IsDate(#2/29/2004#) returns True
? IsDate(#2/29/2005#) returns an error.
 
Here is a function that will test this for you:

Public Function IsThisALeapYear(intYearToTest As Integer) As Boolean
' Returns True if intYearToTest is a leap year; False if not
IsThisALeapYear = (DateSerial(intYearToTest, 3, 1) <>
DateSerial(intYearToTest, 2, 29))
End Function
 
fredg said:
Check for whether 2/29/xxxx is a date:
In the debug window
? IsDate(#2/29/2004#) returns True
? IsDate(#2/29/2005#) returns an error.

You can use that method without raising an error.

?IsDate("2/29/2004")
True
?IsDate("2/29/2005")
False
 
any code to calculate whether a certain year is a leap
year

IsLeap = (Month(DateSerial(YearNum, 2,29))=2)


or the independent way:

IsLeap = (((YearNum Mod 4)=0) And _
((YearNum Mod 100)>0) _
) Or _
((YearNum Mod 400)=0)


Hope that helps


Tim F
 
Back
Top