Calculation Issues

Sum DATEDIF Years, Months, and Days by Condition in Excel

Maira MehtabMaira Mehtab Dec 2, 2026 868 views

Question details

Sum the years, months, and days calculated by DATEDIF only for rows that meet a condition.

Sum DATEDIF Years, Months, and Days by Condition in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains start and end dates for multiple rows and a TRUE or FALSE condition for each row.
Observed behavior
The desired result is a separate total for each DATEDIF component across rows where the condition is TRUE.
Before you start

Check that the start and end cells contain valid dates, each end date is on or after its start date, and the condition cells contain logical TRUE or FALSE values. The examples use start dates in column A, end dates in column B, and conditions in column C.

Solution 1Recommended

Sum each DATEDIF component with SUMIFS

Use helper columns to calculate each date component, then total the components separately for matching rows.

1
Calculate completed years

In cell D2, enter =DATEDIF(A2,B2,"Y") to calculate completed years for the first row.

2
Calculate remaining months and days

In E2, enter =DATEDIF(A2,B2,"YM"). In F2, enter =DATEDIF(A2,B2,"MD"). These formulas return the remaining months and days for the row.

3
Fill the formulas down

Select D2:F2 and drag the fill handle down through row 100, or the last row containing valid dates.

4
Sum matching components

In separate result cells, enter =SUMIFS(D2:D100,C2:C100,TRUE), =SUMIFS(E2:E100,C2:C100,TRUE), and =SUMIFS(F2:F100,C2:C100,TRUE) to total years, months, and days respectively. Adjust the ranges to match your data.

Sum each DATEDIF component with SUMIFS
Interpret the totals separately: The three sums are component totals, not necessarily a normalized calendar duration. Excel also documents that DATEDIF with the "MD" unit can produce inaccurate results in some cases; verify day components when accuracy is critical.
Calculate in WPS Spreadsheets

Sum conditional date components in WPS Spreadsheets

Use DATEDIF helper columns and SUMIFS in WPS Spreadsheets to total date components for rows that meet your condition.

  1. 1. Open your worksheet: Open WPS Spreadsheets and use File > Open to select your workbook.
  2. 2. Create date components: With start dates in A and end dates in B, enter =DATEDIF(A2,B2,"Y") in D2, =DATEDIF(A2,B2,"YM") in E2, and =DATEDIF(A2,B2,"MD") in F2.
  3. 3. Fill down: Select D2:F2 and drag the fill handle down to cover the rows containing valid dates.
  4. 4. Sum matching rows: With TRUE or FALSE conditions in column C, enter =SUMIFS(D2:D100,C2:C100,TRUE) in a result cell. Repeat with E2:E100 and F2:F100 for the month and day totals.
Calculate years, months, and days for individual date rangesSum only rows with a TRUE conditionOpen and edit Microsoft Excel XLSX and XLS filesWork with a familiar spreadsheet interface
QA img-9

Frequently Asked Questions

Can I add the year, month, and day totals into one duration?

Not reliably without additional calendar rules. Months have different lengths, so keep the component totals separate or sum the original date differences as elapsed days.

How do I sum rows based on a text condition instead of TRUE?

Replace TRUE in the SUMIFS formula with the text criterion. For example, =SUMIFS(D2:D100,C2:C100,"Active") sums the year components for rows marked Active.

Why does DATEDIF return an error?

Check that both cells contain valid dates and that the end date is not earlier than the start date. Review the formulas in the helper columns for any blank or invalid date cells.

Does the total elapsed-days formula count overlapping periods twice?

Yes. It adds the duration of each matching row, so overlapping days are counted once for each interval that includes them.

Why should I check DATEDIF's MD result?

Microsoft documents that the "MD" unit can produce inaccurate results in some cases. Test the day components against your expected calendar rules before relying on their total.