Date & Time
All versions
◉ 48 views
=DATEDIF()
Calculates the number of days, months, or years between two dates.
Applies To:
Excel for Microsoft 365Excel for Microsoft 365 for MacExcel 2024Excel 2024 for MacExcel 2021Excel 2021 for MacExcel 2019Excel 2016Windows SharePoint Services 3.0
=DATEDIF(start_date,end_date,unit)
Hover argument names in the table for details.
Output typeNumber
Popularity70 / 100
VolatileNo
Dynamic ArrayNo
Download sample .xlsx ▦ Try in Playground
Dedicated file for this function — safe & lightweight · sample data + live formulas
⬇ Download Sample Workbook
A dedicated .xlsx for =DATEDIF() with Persian sample data & live formulas — open in Excel and practice.
- Sheet “Sample” — data table + formula in place
- Sheet “Guide” — syntax, arguments & tips from this page
- Instant & secure (token + rate limit)
Quiz this function
%d questions — syntax, example & errors — test yourself!
◧ Arguments
| Argument | Type | Required | Description |
|---|---|---|---|
start_date |
Date | Required | A date that represents the first, or starting date of a given period. Dates may be entered as text strings within quotation marks (for example, "2001/1/30"), as serial numbers (for example, 36921, which represents January 30, 2001, if you're using the 1900 date system), or as the results of other formulas or functions (for example, DATEVALUE("2001/1/30")). |
end_date |
Date | Required | A date that represents the last, or ending, date of the period. |
unit |
Text | Required | The type of information that you want returned, where:Unit****Returns"Y"The number of complete years in the period."M"The number of complete months in the period."D"The number of days in the period."MD"The difference between the days in start_date and end_date. The months and years of the dates are ignored.Important: We don't recommend using the "MD" argument, as there are known limitations with it. See the known issues section below."YM"The difference between the months in start_date and end_date. The days and years of the dates are ignored"YD"The difference between the days of start_date and end_date. The years of the dates are ignored. |
▣ Examples
Example 1
=DATEDIF(A2, TODAY(), "Y")
Example 2
=DATEDIF(A2, B2, "M")
§ Remarks
- Dates are stored as sequential serial numbers so they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,447 days after January 1, 1900.
- The DATEDIF function is useful in formulas where you need to calculate an age.
- If the start_date is greater than the end_date, the result will be #NUM!.
✦ Tips
- Dates are stored as sequential serial numbers so they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,447 days after January 1, 1900.
- The DATEDIF function is useful in formulas where you need to calculate an age.
⚠ Common Errors
#NUM!
If the start_date is greater than the end_date, the result will be #NUM!.
Fix: Swap the two dates and check the unit
💬 Comments & Q&A 0 approved
🔒 Your comment will be published after review.Share your thoughts — visible after admin approval
No comments yet — be the first!