Written by Allen Wyatt (last updated December 12, 2020)**This tip applies to** Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365

Bob wonders if there is an easy way to determine if the year of a particular date is a leap year, for purposes of calculating interest and number of compounding days.

We all know that if a year is divisible by 4, then it is a leap year, right? Well, actually, that is wrong. So, you can't simply divide a year number by 4, as in the following, to determine if it is a leap year:

=IF(MOD(YEAR(A1), 4) = 0, "Leap", "Regular")

The formula will work for all dates within this century (years 2000 through 2099), but it won't work reliably outside that range. The reason is because "divisible by 4" is not the only test for a leap year. If the year is a century year (divisible by 100), then it is a leap year only if it is divisible by 400. So the year 2000 is a leap year, but the year 2100 is not.

If you want a bulletproof way to determine if a date occurs within a leap year, then your formula needs to be more complex:

=IF(OR(AND(MOD(YEAR(A1),4)=0,MOD(YEAR(A1),100)>0), MOD(YEAR(A1),400)=0),"Leap","Regular")

Note that this is a single formula; it is shown here on two lines so it fits fully on the screen. The formula tests all three conditions that are necessary to determine if a date falls within a leap year.

Of course, a different approach is to simply figure out if a given year has a February 29 within it. There are any number of formulas that could be used to accomplish this task:

=IF(DAY(EOMONTH("1Jan"&YEAR(A1),1))=29, "Leap", "Regular") =IF(MONTH(DATE(YEAR(A1),2,29))=2, "Leap", "Regular") =IF(DAY(DATE(YEAR(A1),2,29))=29, "Leap", "Regular") =IF(DAY(DATE(YEAR(A1),3,0))=29, "Leap", "Regular")

Any of the methods described so far work fine for any date supported by Excel, with one exception. Those that use the DATE function (the last three shown above) won't work if the date in cell A1 is in the year 1900. Those will always return that 1900 is a leap year, even though it is not. (Interestingly enough, the EOMONTH function doesn't exhibit the same problem as the DATE function does in this regard.)

If you need to work with dates that are before those supported by Excel (before January 1, 1900), then you'll need to work with years directly instead of pulling the year from an Excel date. The variation on the three-test formula will work just fine, if cell A1 contains only a year:

=IF(OR(AND(MOD(A1,4)=0,MOD(A1,100)>0),MOD(A1,400)=0),"Leap","Regular")

You could also create a user-defined function that would test the date. This approach will work just fine regardless of whether the cell contains a date value or a text value for a date. (If you enter an unsupported date value into a cell—such as 1/1/1896—then Excel treats the entry as a text value rather than trying to parse it as a date.) The following example works correctly with all dates supported by VBA, which is in the range of the year 100 through the year 9999:

Function IsLeap1(c As Range) As Boolean YearNo = Year(c.Value) If YearNo Mod 100 = 0 Then IsLeap1 = ((YearNo \ 100) Mod 4 = 0) Else IsLeap1 = (YearNo Mod 4 = 0) End If End Function

To use the function in your worksheet you would enter a formula such as this:

=IF(IsLeap1(A1),"Leap", "Regular")

The following single-line macro works by using the trick of figuring out if there is a February 29 in the year in question:

Function IsLeap2(c As Range) IsLeap2 = IsDate("2/29/" & Year(c.Value)) End Function

The macro is referenced the same way in your worksheet as the previous macro:

=IF(IsLeap2(A1),"Leap", "Regular")

If you need more creative ways to determine if a date is in a leap year, check out this article:

https://chandoo.org/wp/2012/02/29/check-leap-year-using-excel/

*Note:*

If you would like to know how to use the macros described on this page (or on any other page on the *ExcelTips* sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

*ExcelTips* is your source for cost-effective Microsoft Excel training.
This tip (9978) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

**Solve Real Business Problems** Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out *Microsoft Excel 2013 Data Analysis and Business Modeling* today!

Excel can easily store dates. If you want to increment a date by one month, there are a number of ways you can accomplish ...

Discover MoreDifferent industries and different computer systems specify dates in all sorts of strange ways. If you need to convert a ...

Discover MoreYou can use a couple of different worksheet functions to enter today's date in a cell. What if you want to calculate ...

Discover More**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

2021-03-02 08:58:33

Peter Atherton

https://www.contextures.com/leapyearexcelcalcs.html

It compares a country before carrying out a calculation for julian or gregorian leapyear.

2021-01-17 06:18:07

Peter Atherton

2021-01-16 10:39:32

Peter Atherton

2020-12-15 16:11:07

J. Woolley

Nice try, but your function needs more testing. For example, the following return TRUE:

=isLeapYear(1/15/2021)

=isLeapYear(TODAY()+31)

2020-12-14 19:41:11

Peter Atherton

If you need to use dates prior to 1900 this might help

Function isLeapYear(ByVal ref)

Dim bLeap As Boolean, myyear As Long

With WorksheetFunction

If .IsText(ref) Then

myyear = Right(ref, 4)

ElseIf .IsNumber(ref) And Len(ref) = 4 Then

myyear = ref

ElseIf IsDate(ref) Then

myyear = Year(ref)

End If

If myyear Mod 4 = 0 Then

If myyear Mod 100 = 0 And myyear Mod 400 = 0 Then

bLeap = True

ElseIf myyear Mod 100 > 0 And myyear Mod 4 = 0 Then

bLeap = True

End If

End If

End With

Result:

isLeapYear = bLeap

End Function

(see Figure 1 below)

**Figure 1.**

2020-12-14 04:15:59

Willy Vanhaelen

@ Elliot

Oops my typo: "The \ operator performs an integer division: ..."

2020-12-14 04:11:00

Willy Vanhaelen

It is not a typo. The / operator performs a integer division: 10 \ 3 = 3 while 10 / 3 = 3.333...

Got a version of Excel that uses the
ribbon interface (Excel 2007 or later)?
**This site is for you!** If you
use an earlier version of Excel, visit
our *ExcelTips* site focusing on the menu interface.

**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

Copyright © 2023 Sharon Parq Associates, Inc.

## Comments