DATEDIF Function in Excel

Master the DATEDIF function to calculate date differences in years, months, or days. Learn syntax, examples, and solutions to common errors.

ExcelExcel
Google SheetsGoogle Sheets
date-time
intermediate
Syntax Preview
ExcelExcelGoogle SheetsGoogle Sheets
=DATEDIF(start_date, end_date, unit)
Quick Answer
Comprehensive Explanation
How to Use DATEDIF - Step by Step

Practical Examples

Calculate Employee Age

Determine an employee's age for benefits eligibility

Result: 42

Project Duration in Days

Calculate total project duration for billing purposes

Result: 92

Service Anniversary Calculation

Calculate years and months of employment for anniversary recognition

Result: 5 years, 3 months

Subscription Expiry Countdown

Calculate days until subscription renewal

Result: 45

Detailed Age Breakdown

Calculate age in years, months, and days format

Result: 42 years, 6 months, 14 days

Contract Period Validation

Check if contract meets minimum 6-month requirement

Result: Valid

Common Errors and Solutions

#NUM!

DATEDIF returns #NUM! error

Cause:

The start_date is later than the end_date, resulting in a negative date difference

Solution:

1. Verify date order - start_date must be earlier 2. Swap the dates if they're reversed 3. Use IF statement to check: =IF(A2>B2, "Invalid dates", DATEDIF(A2,B2,"D")) 4. Consider using ABS() with DAYS function as alternative

Prevention:

Always validate that start_date <= end_date before using DATEDIF. Create a helper column to check date order first.

Frequency: 45%

Example:

#VALUE!

DATEDIF returns #VALUE! error

Cause:

One or both date arguments are not recognized as valid dates, or the unit parameter is incorrect

Solution:

1. Check that both dates are properly formatted 2. Verify the unit parameter is in quotes: "Y", "M", "D", etc. 3. Use DATEVALUE() to convert text dates 4. Ensure cells don't contain text or spaces

Prevention:

Use DATE function to create dates or DATEVALUE to convert text. Always put unit parameter in quotes.

Frequency: 30%

Example:

#NAME?

Excel doesn't recognize DATEDIF function

Cause:

Typo in function name or the quotes around unit parameter are missing or incorrect

Solution:

1. Verify spelling: DATEDIF (not DATEIF or DATEDIFF) 2. Ensure unit parameter has straight quotes " not curly quotes 3. Check Excel version supports DATEDIF 4. Don't rely on autocomplete - type manually

Prevention:

Type DATEDIF manually as it won't appear in autocomplete. Always use straight quotes for the unit parameter.

Frequency: 20%

Example:

Incorrect Result

DATEDIF returns unexpected values with "MD" unit

Cause:

The "MD" unit can produce incorrect results in some Excel versions when days in start month exceed days in end month

Solution:

1. Use alternative calculation: =DAY(end_date)-DAY(start_date) 2. For accurate results, use: =end_date-DATE(YEAR(end_date),MONTH(end_date),1)+1 3. Test with known values first 4. Consider using "D" unit and calculating remainder manually

Prevention:

Be cautious with "MD" unit, especially for dates at month boundaries. Test thoroughly or use alternative formulas.

Frequency: 5%

Example:

Best Practices and Advanced Tips

Create comprehensive duration displays by combining multiple DATEDIF functions. Use concatenation to show years, months, and days: =DATEDIF(A2,B2,"Y") & " years, " & DATEDIF(A2,B2,"YM") & " months"

DATEDIF is undocumented in Excel and won't appear in formula autocomplete or the Insert Function dialog. You must type it manually. Despite this, it's fully supported and works reliably in all Excel versions since 2000.

Combine DATEDIF with TODAY() or NOW() for automatically updating calculations like age, tenure, or countdown timers. The formula updates whenever the spreadsheet recalculates.

Wrap DATEDIF in an IF statement to handle cases where dates might be reversed. This prevents #NUM! errors and provides user-friendly messages.

DATEDIF works with your system's date settings. When sharing spreadsheets internationally, be aware that date formats vary (MM/DD/YYYY vs DD/MM/YYYY). Use DATE function or cell formatting to ensure consistency.

DATEDIF vs Alternative Functions
Frequently Asked Questions

Need Help with DATEDIF Function in Excel?

Stop struggling with formula syntax. Use AskFormulas to generate validated formulas instantly with our AI-powered tool.

Example Excel formula:

Related Formulas

DATE Function in Excel

Master the DATE function in Excel to create dates from year, month, and day values. Learn syntax, examples, errors, and best practices.

beginner
date-time
ExcelExcel
Google SheetsSheets
Validated
DAY Function in Excel & Sheets

Extract the day number from any date with the DAY function. Learn syntax, examples, and solutions to common errors for both Excel and Google Sheets.

beginner
date-time
ExcelExcel
Google SheetsSheets
Validated
NOW Function

The NOW function returns the current date and time, updating automatically when the spreadsheet recalculates. Perfect for timestamps and real-time tracking.

beginner
date-time
ExcelExcel
Google SheetsSheets
Validated
TODAY Function

Master the TODAY function to insert dynamic current dates that update automatically. Learn practical examples and avoid common errors.

beginner
date-time
ExcelExcel
Google SheetsSheets
Validated