ThisCalculator

Everyday

DATEDIF Excel: Calculate Date Difference

Updated · Standard formula, shown below

Difference in days 1,169 days
Start date (e.g. 1/1/2020)
43831
You entered
End date (e.g. 6/15/2023)
45000
You entered

DATEDIF in Excel calculates the difference between two dates in days, months, or years. You enter a start date, an end date, and a unit code, and it returns the completed number of that unit between them. It is a hidden function, so it won’t appear in the formula autocomplete list, but typing it manually works in all current versions of Excel.

Formula

The DATEDIF function uses this syntax:

=DATEDIF(start_date, end_date, unit)

Where:

  • start_date is the earlier date (a cell reference or a date entered with DATE()).
  • end_date is the later date. If it is earlier than start_date, Excel returns a #NUM! error.
  • unit is a text code in quotes: “Y” for complete years, “M” for complete months, “D” for days, “MD” for days ignoring months and years, “YM” for months ignoring years, and “YD” for days ignoring years.

All dates in Excel are stored as serial numbers, where 1 equals January 1, 1900. Subtracting two dates gives the number of days between them, and DATEDIF breaks that difference into the unit you request.

Worked Example

Using the calculator above with start date 43831 (January 1, 2020) and end date 45000 (March 15, 2023):

  1. Subtract the serial numbers: 45000 – 43831 = 1169 days.
  2. The raw day difference is 1169 days.
  3. For complete years: 2023 – 2020 = 3, but because March 15 is before January 1 in the same year, the count is 3 full years (2020, 2021, 2022).
  4. For complete months: 3 years × 12 = 36 months, plus the months from January to March = 2, so 38 months. The calculator’s day difference is 1169 days.

So with those inputs, DATEDIF(“1/1/2020”, “3/15/2023”, “D”) returns 1169, which matches the calculator’s output.

How DATEDIF Works

DATEDIF is a compatibility function from Lotus 1-2-3. Microsoft kept it in Excel but never listed it in the Function Wizard or the Insert Function dialog. It works in every version from Excel 2000 through Excel 365, but you must type the name yourself.

The unit codes control what you get:

  • “Y” – complete years between the two dates.
  • “M” – complete months between the two dates.
  • “D” – total days between the two dates.
  • “MD” – days between the two dates, ignoring months and years. Useful for finding the day-of-month difference.
  • “YM” – months between the two dates, ignoring years. Useful for finding the month-of-year difference.
  • “YD” – days between the two dates, ignoring years. Useful for finding the day-of-year difference.

The function counts only complete units. For example, from January 1 to March 1, “M” returns 2, not 2.1. From January 1 to February 1, “Y” returns 0, not 0.08.

Choosing the Right Unit

Pick the unit based on what you need to measure:

  • Age in years: use “Y”.
  • Billing cycles or lease terms: use “M”.
  • Days until a deadline: use “D”.
  • Days between anniversaries ignoring the year: use “YD”.
  • Months between two dates in the same year: use “YM”.
  • Days between two dates in the same month: use “MD”.

For example, to find someone’s age in years, months, and days, you can combine three DATEDIF formulas: =DATEDIF(A1,B1,"Y"), =DATEDIF(A1,B1,"YM"), and =DATEDIF(A1,B1,"MD"). This is a common way to display a full age.

Common Mistakes and Errors

The most frequent issues with DATEDIF are:

  • End date before start date – returns #NUM! because the function expects the first date to be earlier.
  • Unit not in quotes – typing Y instead of “Y” treats it as a named range and returns #NAME?.
  • Dates entered as text – if you type “1/1/2020” as text, Excel may not recognize it as a date. Use DATE(2020,1,1) or a cell with a real date.
  • Using “MD” with month-end dates – can give odd results. For example, from January 31 to February 28, “MD” returns 28, because it counts days after ignoring months, and February has no 31st.
  • Expecting inclusive counting – DATEDIF counts the difference, not the number of days including both endpoints. From January 1 to January 2, “D” returns 1, not 2.

If you get a #VALUE! error, check that both dates are valid Excel dates. If you get #NUM!, check the order.

Alternatives to DATEDIF

If you prefer not to use a hidden function, you have other options:

  • Simple subtraction – =B1-A1 gives the number of days between two dates, because dates are serial numbers.
  • DAYS function – =DAYS(end_date, start_date) returns the same day count and is visible in the function list.
  • YEARFRAC function – returns the fraction of a year between two dates, with a basis argument for day-count conventions (e.g., 30/360, actual/365). Useful for financial calculations.
  • EDATE and EOMONTH – add or subtract months from a date, which can help with month-based calculations.

For most day counts, simple subtraction works fine. For months and years, DATEDIF is the most direct tool, but you must remember to type it manually.

Frequently Asked Questions

Why don’t I see DATEDIF in the function list?
Microsoft intentionally hides it for compatibility with Lotus 1-2-3. It still works, but it doesn’t appear in the Insert Function dialog or the formula autocomplete. Type =DATEDIF( manually and it will work.

What is the difference between DATEDIF and DAYS?
DAYS only returns the total number of days between two dates. DATEDIF can return days, months, or years, and with the “MD”, “YM”, and “YD” codes, it can return partial differences ignoring larger units.

How do I calculate age in years and months with DATEDIF?
Use two formulas: =DATEDIF(A1,B1,"Y") for years and =DATEDIF(A1,B1,"YM") for remaining months. Combine them in a text string like =DATEDIF(A1,B1,"Y")&" years, "&DATEDIF(A1,B1,"YM")&" months".

Does DATEDIF work with dates in different years?
Yes, it handles any valid start and end date, as long as the start date is earlier. The “Y”, “M”, and “D” codes count total units across all years. The “YM” and “YD” codes ignore years, so they only work on the month/day portion.

Why does DATEDIF return 0 for months between January 31 and February 28?
Because “M” counts complete months. From January 31 to February 28 is not a full month (February has no 31st), so it returns 0. If you want days instead, use “D” or “MD”.

Can I use DATEDIF with dates stored as text?
No, DATEDIF requires real date values. If your dates are text, convert them with DATEVALUE() or use the DATE() function to create valid dates.

Related

Formula used
in t | Start date (e.g. 1/1/2020) | - | 43831 | 0
in d | End date (e.g. 6/15/2023) | - | 45000 | 0
out diff | Difference in days | days | d - t | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.