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.




=DATEDIF(start_date, end_date, unit)
Practical Examples
Calculate Employee Age
Determine an employee's age for benefits eligibility
Project Duration in Days
Calculate total project duration for billing purposes
Service Anniversary Calculation
Calculate years and months of employment for anniversary recognition
Subscription Expiry Countdown
Calculate days until subscription renewal
Detailed Age Breakdown
Calculate age in years, months, and days format
Contract Period Validation
Check if contract meets minimum 6-month requirement
Common Errors and Solutions
DATEDIF returns #NUM! error
The start_date is later than the end_date, resulting in a negative date difference
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
Always validate that start_date <= end_date before using DATEDIF. Create a helper column to check date order first.
Example:
DATEDIF returns #VALUE! error
One or both date arguments are not recognized as valid dates, or the unit parameter is incorrect
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
Use DATE function to create dates or DATEVALUE to convert text. Always put unit parameter in quotes.
Example:
Excel doesn't recognize DATEDIF function
Typo in function name or the quotes around unit parameter are missing or incorrect
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
Type DATEDIF manually as it won't appear in autocomplete. Always use straight quotes for the unit parameter.
Example:
DATEDIF returns unexpected values with "MD" unit
The "MD" unit can produce incorrect results in some Excel versions when days in start month exceed days in end month
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
Be cautious with "MD" unit, especially for dates at month boundaries. Test thoroughly or use alternative formulas.
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.
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
Master the DATE function in Excel to create dates from year, month, and day values. Learn syntax, examples, errors, and best practices.


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.


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


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

