Back to Articles

Mastering Excel DATEDIF Function: Complete Guide to Date Difference Calculations

Function Overview

The DATEDIF function (Date Difference) is Excel's best-kept secret for date calculations. Originally from Lotus 1-2-3, this undocumented function has been available since Excel 2007. It calculates complete intervals between two dates in years, months, or days.

Syntax Structure

=DATEDIF(start_date, end_date, "unit")

Parameter Details

6 Unit Codes Explained

Unit CodeCalculationExample
"Y"Complete years2020-01-01 to 2023-12-31 → 3
"M"Complete months2023-01-15 to 2023-03-14 → 1
"D"Total days2023-01-01 to 2023-01-31 → 30
"MD"Days excluding months/years2023-01-15 to 2023-03-10 → 25
"YM"Months excluding years2022-11-30 to 2023-02-28 → 3
"YD"Days excluding years2024-02-28 to 2025-03-01 → 31

Practical Use Cases

Case 1: Dynamically calculate age

=DATEDIF(B2,TODAY(),"Y")&" years "&DATEDIF(B2,TODAY(),"YM")&" months"

Look at the example below and copy and paste the data below into the Excel file.

ID	Birth Date (Column B)	Age (Years & Months) (Column C)	Formula Explanation
1	2010-05-15	15 years 5 months	Calculates time from 2010-05-15 to today (2025-10-14)
2	2020-12-20	4 years 10 months	Calculates time from 2020-12-20 to today (2025-10-14)
3	1995-03-08	30 years 7 months	Calculates time from 1995-03-08 to today (2025-10-14)
4	2025-07-01	0 years 3 months	Calculates time from 2025-07-01 to today (2025-10-14)
5	1988-10-14	37 years 0 months	Calculates time from 1988-10-14 to today (2025-10-14) – Birthday of the current year
To use it in Excel, simply enter the formula in cell C2 and fill down to apply it to other rows.

Mastering Excel DATEDIF Function: Complete Guide to Date Difference Calculations

You can delete the age column and then apply the formula above to test the effect.

Case 2: Non-working Days

=DATEDIF(start_date,end_date,"D")-NETWORKDAYS(start_date,end_date,holidays)

This Excel formula is used to calculate the number of non-working days between two dates (including weekends and specified holidays).
Formula principle:

The following is a test table that calculates three indicators: total number of days (DATEDIF), number of working days (NETWORKDAYS), and number of non-working days (difference).

Project Name	Start Date	End Date	Total Days (Formula 1)	Working Days (Formula 2)	Non-working Days (Formula 3)
Project A	2023-10-09	2023-10-15	=DATEDIF(B2,C2,"D")	=NETWORKDAYS(B2,C2)	=D2-E2
Project B	2023-12-20	2023-12-26	=DATEDIF(B3,C3,"D")	=NETWORKDAYS(B3,C3)	=D3-E3
Project C	2024-01-08	2024-01-14	=DATEDIF(B4,C4,"D")	=NETWORKDAYS(B4,C4)	=D4-E4
The result of the calculation is

Mastering Excel DATEDIF Function: Complete Guide to Date Difference Calculations

Error Troubleshooting

Critical Considerations

  1. Leap Year Handling:
    2020-02-29 to 2021-02-28 → Returns 1 year with "Y" unit
  2. Month-End Quirk:
    =DATEDIF("2023-01-31","2023-03-01","MD") returns 1 day (not 0)
  3. Date Format Best Practice:
    Always use DATE function for unambiguous calculations

Real-World Application

A logistics company improved their invoice processing by 35% using DATEDIF to calculate payment terms:

When to Use Alternatives

While powerful, consider other methods for:

Pro Tips

Last verified: Excel 365 (August 2023 release)