Sum DATEDIF Years, Months, and Days by Condition in Excel
Question details
Sum the years, months, and days calculated by DATEDIF only for rows that meet a condition.

- 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.
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.
Sum each DATEDIF component with SUMIFS
Use helper columns to calculate each date component, then total the components separately for matching rows.
In cell D2, enter =DATEDIF(A2,B2,"Y") to calculate completed years for the first row.
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.
Select D2:F2 and drag the fill handle down through row 100, or the last row containing valid dates.
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.

Calculate total elapsed days for matching rows
Use the original dates when you need one additive duration rather than separate year, month, and day totals.
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. Open your worksheet: Open WPS Spreadsheets and use File > Open to select your workbook.
- 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. Fill down: Select D2:F2 and drag the fill handle down to cover the rows containing valid dates.
- 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.

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.




