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:

http://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 Office 365.

**Professional Development Guidance!** Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out *Professional Excel Development* today!

If you use Excel to maintain a collection of data, you may need to find information in one column based on information in ...

Discover MoreCalculating a retirement date can be as simple as doing some date math to see when a person reaches a certain age. ...

Discover MoreWhen you have a huge amount of daily data to analyze, you may want to calculate an average of values for any given date ...

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

2018-01-31 10:14:24

Willy Vanhaelen

For all years in the Gregorian calendar, including those before 1900 this formula is the shortest to determine a leap year (A1 contains only the year):

=IF(MOD(A1,4)+(MOD(A1,100)=0)-(MOD(A1,400)=0),"regular","leap")

Here some examples of how it works:

For 1900:

MOD(1900,4) -> 0

(MOD(1900,100)=0) -> TRUE=1

(MOD(1900,400)=0) -> FALSE=0

0+1-0=1 (TRUE) -> regular

For 2000:

MO0(2000,4) -> 0

(MOD(2000,100)=0) -> TRUE=1

(MOD(2000,400)=0) -> TRUE=1

0+1-1=0 (FALSE) -> leap

For 2018:

MO0(2018,4) -> 2

(MOD(2018,100)=0) -> FALSE=0

(MOD(2018,400)=0) -> FALSE=0

2+0-0=2 (TRUE) -> regular

...

2015-05-18 12:04:11

Michael (Micky) Avidan

I was referring to the few last(!) COMMENTS (not in Allan's tip) whereas none of the suggestions handles the year 1900.

I, usually, don't look for "excuses" (especially not from MS).

As far as I recall, my suggested formula was the shortest among Allan's formulas that work.

Am I wrong at that point ? (Length of formula).

Michael (Micky) Avidan

“Microsoft® Answers" - Wiki author & Forums Moderator

ISRAEL

2015-05-18 03:17:06

Tony Davis

The second formula works for all years incl. 1900 wheras the other formulas are only wrong for 1900 and Microsoft explain the reasoning for that.

The article also clearly indicates that most of these formula don't work for 1900 and clearly states the "bulletproof" formula that does work for 1900.

2015-05-17 08:09:11

Michael (Micky) Avidan

With all due respect - none of the formulas, in the suggest comments handles correctly the year 1900.

Michael (Micky) Avidan

“Microsoft® Answers" - Wiki author & Forums Moderator

“Microsoft®” MVP – Excel (2009-2015)

ISRAEL

2015-05-16 15:05:03

Bruce Osterberg

2015-05-16 11:49:52

Ron Fiorito

=DATE(YEAR(A1)+1,1,1)-DATE(YEAR(A1),1,1)

Ron

2015-05-16 11:18:44

John Hamm

=IF(ISERROR(DATEVALUE("2/29/"&YEAR(A1))),"Regular","Leap")

2015-05-16 11:09:55

Ron Fiorito

=MONTH(DATE(YEAR(A1),1,0)+60)-2

This formula returns a zero if it’s a leap year, or 1 if it is not. Shorter and simpler.

If you wanted a TRUE/FALSE result, just add =0 to the end like this:

=MONTH(DATE(YEAR(A1),1,0)+60)-2=0

This will return TRUE if it’s a leap year, or FALSE if it is not.

These work for all supported dates except for the buggy year 1900.

Ron

2015-05-16 10:56:18

Richard Zawadzki

If Bob was counting the number of days for interest purposes, and was working on historical dates, he'd better know the relevant country and the relevant calendar (China removed 12 days 1911/1912, Turkey removed 13 days in 1926/1927, Japan removed 12 days in 1872/1873, US Canada and UK removed 11 days in 1752)

Richard

2015-05-16 10:39:11

Richard Zawadzki

So, you can use this formula:

=IF(MONTH(DATE(YEAR(A1),2,29))=2,"Leap","Regular")

Richard Z

2015-05-16 06:47:04

Michael (Micky) Avidan

Therefore this must be taken into consideration – so, my contribution, to Bob's original question, was:

=(MOD(A1,4)=0)*(MOD(A1,100)<>0)+(MOD(A1,400)=0)>0

(While cell A1 holds only the year)

If pone needs to check over a full date then:

=(MOD(YEAR(A1),4)=0)*(MOD(YEAR(A1),100)<>0)+(MOD(YEAR(A1),400)=0)>0

*** Returning TRUE for a Leap year and FALSE for a Regular year.

Michael (Micky) Avidan

“Microsoft® Answers" - Wiki author & Forums Moderator

“Microsoft®” MVP – Excel (2009-2015)

ISRAEL

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 © 2020 Sharon Parq Associates, Inc.

## Comments