
π This article includes 1 downloadable practice file β
In this article
DATEDIF is a hidden function (not in the autocomplete list) that returns the difference between two dates in completed years, months or days.
Syntax
=DATEDIF(start_date, end_date, unit)
| Argument | What it means |
|---|---|
unit |
“y” years, “m” months, “d” days, “ym” months after years, “md” days after months. |
Examples
Example 1
=DATEDIF(B2, TODAY(), "y")
Age in completed years.
Example 2
=DATEDIF(B2,TODAY(),"y")&" y "&DATEDIF(B2,TODAY(),"ym")&" m"
Tenure like β5 y 3 mβ.
Common errors and fixes
| You see | Why, and the fix |
|---|---|
#NUM! |
start_date is after end_date. |
DATEDIF in practice
Where you will use it
- Age in completed years
- Service length for gratuity (years and months)
- Months a loan has run
Worked example
| Start | End | Formula | Result |
|---|---|---|---|
| 15-Aug-1990 | 04-Oct-2026 | =DATEDIF(A2,B2,"y")&" y "&DATEDIF(A2,B2,"ym")&" m" | 36 y 1 m |
| 01-Apr-2021 | 04-Oct-2026 | =DATEDIF(A3,B3,"y")&" y "&DATEDIF(A3,B3,"ym")&" m" | 5 y 6 m |
| 31-Jan-2026 | 01-Mar-2026 | =DATEDIF(A4,B4,"y")&" y "&DATEDIF(A4,B4,"ym")&" m" | 0 y 1 m |
Results calculated in Excel.
Mistakes people make
| Mistake | What to do instead |
|---|---|
| Start after end gives #NUM! | Put the earlier date first |
| It's not in the function list | DATEDIF is hidden but works; type it fully |
Related functions
π Part of the free Excel course: Beginner β Expert Β· Try it in the Formula Lab or ask the AI Helper.
Test formulas dynamically in our web formula laboratory or download the companion Excel workbook.
π Practice files for this article
- πPractice workbook: Dates & times22 tasks on realistic sales data β type your formula, the Check column turns green when it is right. Answers sheet included.β¬ XLSX Β· 34 KB
Free to use for learning. Files with macros (.bas) are plain text β import them with Alt+F11 β File β Import File, and always test on a copy.
Atul (AJ) builds office-automation and local-first AI tools as Atulya AI, and works with Excel, SAP and Oracle EPM every day. He writes about the shortcuts, macros and automations that actually save time β plus the occasional wacky fact. Videos on YouTube: Lazy Automator AI (@LazyAutomatorAI).
More posts by Atul βBuild this skill next
This page is a quick function reference. Use it for syntax, then practise the function in a broader workflow.
Stuck on a step? Ask a question and the AI answers using this article.