Navigation: home » code » isleapyear

IsLeapYear() (VB Function)

A Visual Basic function that takes a given year (in the same range as an integer) and returns TRUE or FALSE depending on whether it is a leap year or not. This question seems to crop up a lot in certain places, so it’s here for reference.

Usage:

MsgBox IsLeapYear(1984)
' Returns TRUE
 
MsgBox IsLeapYear(1900)
' Returns FALSE

The function:

' A function that will determine whether a given year is a leap
' year or not.
Public Function IsLeapYear(Year As Integer) As Boolean
    IsLeapYear = (((Year Mod 4 = 0) And (Year Mod 100 <> 0)) Or Year Mod 400 = 0)
End Function