How to Count Leap Years Between Two Dates in Excel

📅 Apr 06, 2026 📝 Sarah Miller

Accurately accounting for leap years in long-term financial models or contract tracking is a notoriously tedious struggle for analysts. While standard tools like YEARFRAC or basic division offer quick approximations, they often smooth over the exact impact of February 29, leading to compounding calculation discrepancies over time.

Transitioning to advanced date formulas grants users absolute, audit-ready precision. Under the stipulation that the formula must programmatically isolate February 29 for every year within your specific range, we must employ logical arrays. For example, utilizing a combination of SUMPRODUCT, DATE, and ROW functions serves as a foolproof method to verify and count each leap day.

Below, we will detail the exact formula syntax and provide a step-by-step breakdown to seamlessly integrate this solution into your active worksheets.

How to Count Leap Years Between Two Dates in Excel

Calculating time spans in Microsoft Excel is a foundational skill for financial analysts, project managers, HR professionals, and data scientists. While finding the difference between two dates is usually as simple as subtracting one cell from another, factoring in anomalies like leap years introduces a layer of complexity. Excel does not feature a built-in, standalone COUNTLEAPYEARS function. Therefore, mastering the formulas required to identify and count leap years within a specific date range is essential for building highly accurate models.

This comprehensive guide explores why counting leap years is vital, breaks down the mathematical logic of a leap year, and provides several robust, step-by-step Excel formulas to handle this task-ranging from classic, backward-compatible array formulas to modern, streamlined Office 365 solutions.

Why Does Counting Leap Years Matter?

A calendar year is typically 365 days long. However, because the Earth takes approximately 365.2422 days to orbit the Sun, we add an extra day-February 29th-nearly every four years to keep our calendar aligned with the astronomical seasons. This extra day is known as a leap day, and the year containing it is a leap year.

In professional Excel modeling, ignoring leap years can lead to cumulative errors in several areas:

  • Financial Modeling & Interest Accrual: Many financial contracts utilize day-count conventions (such as ACT/365 or ACT/366). Miscounting leap days can lead to incorrect interest calculations and billing discrepancies.
  • HR & Payroll: Calculating precise tenure, retirement eligibility, or accrued benefits over long career spans requires accounting for every single elapsed day.
  • Project Management: When planning multi-year infrastructural projects, missing a leap day can throw off precise shipping schedules, milestone deadlines, and resource allocations.

The Logic of a Leap Year

Before writing an Excel formula, we must establish the mathematical rules that define a leap year. Under the Gregorian calendar, a year is a leap year if it meets the following conditions:

  1. The year must be evenly divisible by 4.
  2. If the year is evenly divisible by 100, it is not a leap year, unless...
  3. The year is also evenly divisible by 400.

For example, the year 2000 was a leap year because it is divisible by 400. The years 1700, 1800, and 1900 were not leap years because they are divisible by 100 but not 400. In Excel, we can replicate this logic using the MOD function, or we can leverage Excel's native date engine, which inherently understands leap years.


Method 1: The Elegant SUMPRODUCT & DATE Formula (Classic Excel)

The most reliable classic approach for counting leap years between a start date in cell A2 and an end date in cell B2 involves checking the last day of February for every year within that range. If the last day of February in a given year is the 29th, that year is a leap year.

The Formula

=SUMPRODUCT(--(DAY(DATE(ROW(INDIRECT(YEAR(A2)&":"&YEAR(B2))),3,0))=29))

How It Works

This formula may look intimidating at first glance, but it is incredibly elegant when broken down step-by-step:

  1. YEAR(A2) and YEAR(B2): These extract the starting and ending years of your date range. If A2 is 2019-05-15 and B2 is 2025-08-20, this returns 2019 and 2025.
  2. INDIRECT(YEAR(A2)&":"&YEAR(B2)): This creates a text string representing a range of rows, in this case, "2019:2025". The INDIRECT function converts this text string into an actual reference that Excel can evaluate.
  3. ROW(...): When wrapped around our indirect row reference, the ROW function generates an array of numbers representing every year in the range: {2019; 2020; 2021; 2022; 2023; 2024; 2025}.
  4. DATE(ROW(...), 3, 0): In Excel, requesting day 0 of March (month 3) acts as a backward offset, returning the final day of February for each year in our array. For 2019, it returns February 28; for 2020, it returns February 29.
  5. DAY(...): This extracts the day number from those end-of-February dates. It generates an array of days: {28; 29; 28; 28; 28; 29; 28}.
  6. =29: This compares each value in the array to 29, returning a boolean array of TRUE and FALSE values: {FALSE; TRUE; FALSE; FALSE; FALSE; TRUE; FALSE}.
  7. The Double Unary Operator (--): This converts the TRUE and FALSE values into 1s and 0s, resulting in: {0; 1; 0; 0; 0; 1; 0}.
  8. SUMPRODUCT(...): Finally, SUMPRODUCT sums this array, returning 2. There are two leap years (2020 and 2024) in this range.

Method 2: Counting Actual Leap Days Crossed (The Precise Financial Method)

While Method 1 tells you how many leap years overlap your date range, it doesn't account for whether the range actually spans across the leap day (February 29th) of those years. For instance, if your range is from March 1, 2024 to December 31, 2025, the year 2024 is a leap year, but the leap day (February 29, 2024) has already passed and is outside your range.

To count only the actual February 29ths that fall between your start and end dates, use this advanced formula:

The Formula

=SUMPRODUCT(--(MONTH(DATE(ROW(INDIRECT(YEAR(A2)&":"&YEAR(B2))),2,29))=2)*(DATE(ROW(INDIRECT(YEAR(A2)&":"&YEAR(B2))),2,29)>=A2)*(DATE(ROW(INDIRECT(YEAR(A2)&":"&YEAR(B2))),2,29)<=B2))

How It Works

This formula systematically evaluates every candidate year in your range:

  • It dynamically constructs February 29th for every year: DATE(Year, 2, 29). If a year is not a leap year (like 2023), Excel automatically rolls this date forward to March 1st.
  • Condition 1: MONTH(...) = 2 ensures that the generated date actually stayed in February (meaning it is a valid leap day). If it rolled over to March, it returns FALSE.
  • Condition 2 & 3: >= A2 and <= B2 ensure that the valid February 29th falls strictly within your specific start and end boundaries.
  • The multiplication symbols (*) act as an AND condition in array math, returning 1 only when a valid February 29th falls inside your window.

Method 3: Modern Excel with Office 365 (LET and SEQUENCE)

If you are using Microsoft 365 or Excel 2021, you can avoid the convoluted ROW(INDIRECT(...)) syntax entirely. Modern Excel introduces dynamic arrays, the SEQUENCE function, and the LET function, making formulas much easier to read, write, and maintain.

The Formula

=LET(
    StartYear, YEAR(A2),
    EndYear, YEAR(B2),
    YearsArray, SEQUENCE(EndYear - StartYear + 1, 1, StartYear),
    LeapDays, MAP(YearsArray, LAMBDA(y, IF(MONTH(DATE(y, 2, 29))=2, DATE(y, 2, 29), 0))),
    SUM(--((LeapDays >= A2) * (LeapDays <= B2)))
)

Why Use This Method?

  • Readability: The LET function allows you to define variables (like StartYear and YearsArray), clarifying your logic step-by-step.
  • No Volatility: The classic INDIRECT function is volatile, meaning Excel recalculates it every time any change is made to the sheet, which can slow down large workbooks. SEQUENCE is non-volatile and highly performant.
  • Expressive Power: Using MAP and LAMBDA lets you apply custom logic directly to each year in your range, offering a clean programming-style workflow directly inside an Excel formula.

Summary Comparison of Methods

Method Target Use Case Pros Cons
Method 1: Classic SUMPRODUCT Counting calendar leap years regardless of specific months. Works on all legacy versions of Excel. Short formula length. Uses the volatile INDIRECT function; doesn't check if Feb 29th was actually crossed.
Method 2: Precise Crossing Financial applications requiring calculation of exact elapsed leap days. Highly accurate; ignores leap days outside the date boundaries. Longer, more complex formula that is difficult to edit.
Method 3: Modern LET & SEQUENCE Clean, high-performance auditing in Excel 365 or Excel 2021+. Non-volatile, extremely easy to read, debug, and scale. Not compatible with older versions of Excel (Excel 2019 or earlier).

Conclusion

Calculating the presence of leap years and leap days doesn't require complex VBA macros or cumbersome helper columns. By nesting logical date checks inside SUMPRODUCT or leveraging Modern Excel's lambda-based functions, you can design dynamic formulas that keep your financial, timeline, or mathematical calculations highly accurate. For most users, Method 2 offers the best compromise of compatibility and functional accuracy, while users of Modern Excel should run, not walk, to adopt Method 3's clean and efficient design.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.