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:
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:
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:
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 you need more creative ways to determine if a date is in a leap year, check out this article:
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 More
Different industries and different computer systems specify dates in all sorts of strange ways. If you need to convert a ...Discover More
You 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."
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.