TodayFree forever - no sign-up, no paid plans

DATEDIF units explained - Y, M, D, YM, MD and YD

By Daniel Mercer · Updated November 18, 2026

Open the Months Between Dates Calculator

The DATEDIF function answers six different questions about the same two dates, and the only thing that changes is a short code in quotation marks - the unit. Pick the wrong unit and the formula still calculates, still looks plausible, and is quietly answering a question you did not ask. This guide takes all six units through one shared example so you can see exactly what each one counts, what each one ignores, and which combinations produce the answers people actually want, like an age in years, months and days.

Our test span: June 1, 2023 to August 25, 2026. In words, that is 3 years, 2 months and 24 days - a total of 1,181 days. Keep those figures in mind as each unit takes its turn. If you are new to the function itself, start with our guide on months between dates in Excel with DATEDIF, then come back here for the full unit tour.

All six units on one span

UnitReturnsWhat it counts
"Y"3Complete years - the birthdays that have passed
"M"38Complete months across the whole span, years included
"D"1,181Every day in the span - plain subtraction would give the same
"YM"2Months left over after the complete years are taken out
"MD"24Days left over after the complete months are taken out
"YD"85Days between the dates ignoring the years, as if in one year
DATEDIF units used to work out a baby's age in months and days

The three plain units: Y, M and D

"Y" - complete years. A year counts only when the anniversary has passed. June 1, 2023 to May 31, 2026 would return 2, not 3, because the third anniversary falls on June 1, 2026. This is the unit behind every age calculation: your age in years is a "Y" count from your date of birth to today.

"M" - complete months. The same idea at month level, with no regard for years: every monthly anniversary in the whole span. Three years and two months is 38 complete months, which is why "M" is the unit for tenancy lengths, contract terms and anything quoted purely in months. It follows the anniversary rule explained in our guide on how to calculate months between two dates.

"D" - all the days. The least mysterious unit. It returns the same figure as subtracting the dates, 1,181 here, and its real job is as a check: any combination of the other units should be reconcilable with it.

The three remainder units: YM, MD and YD

The units with two letters are remainder units: each one first removes part of the span, then counts what is left. "YM" ignores the years: it removes the complete years first, then counts the complete months in what remains. That is why it returns 2 where "M" returns 38. "MD" ignores the months and years: it removes every complete month, then counts the days left, returning 24. "YD" ignores the years only for a day count: it lines the two dates up inside a single year and counts the days between them - June 1 to August 25 is 85 days (29 remaining days of June, 31 in July, 25 in August).

The pattern is consistent once you see it: the first letter is what gets counted, and if there is a second letter, it names what has already been removed. YM counts Months after Years are removed. MD counts Days after Months are removed. YD counts Days after Years are removed. That one sentence will reconstruct the whole table whenever you need it.

The combination that matters: years, months and days

On their own, the remainder units look like trivia. Combined, they produce the most requested answer in all of date counting - an age or a duration stated in years, months and days:

=DATEDIF(A1,B1,"Y")&" years, "&DATEDIF(A1,B1,"YM")&" months, "&DATEDIF(A1,B1,"MD")&" days"

On our test span it returns 3 years, 2 months, 24 days. Check it by adding back: June 1, 2023 plus 3 years is June 1, 2026; plus 2 months is August 1, 2026; plus 24 days is August 25, 2026. Exact. The months between dates calculator on this site shows the same breakdown, and the days between calculator on the homepage confirms the 1,181-day total underneath it.

One honest warning about "MD": very old Excel versions had a known flaw that could make MD return a negative or oversized figure in rare month-end cases. Current versions are correct, but if an MD result ever looks impossible - negative, or above 30 - rebuild it as end date minus EDATE(start date, complete months) instead, as described in the Excel DATEDIF guide. A leftover can never exceed 30 days, a fact worth remembering from our guide on full months vs partial months.

Which unit should you actually use?

For a contract, tenancy or service length quoted in months, use "M" - and pair it with "MD" so the leftover days are visible rather than dropped. For an age, use the Y + YM + MD combination. For a total to feed into interest or per-day costs, use "D". "YD" is the specialist: it shines when the year genuinely does not matter, such as comparing dates within a season, a school year or a growing cycle. And if you are working in Google Sheets rather than Excel, nothing changes - all six units behave identically there, as our Sheets guide shows.

Frequently asked questions

What is the difference between the M and YM units?

M counts every complete month in the whole span, so a span of 3 years and 2 months returns 38. YM first removes the complete years, then counts the months left over, so the same span returns 2. Use M for a total month count, and YM when you are building a years, months and days answer.

What does the MD unit return?

The days left over after the complete months are removed - the partial month, in days. For June 1, 2023 to August 25, 2026, MD returns 24, because after 38 complete months (ending August 1, 2026) there are 24 days left. MD is the unit that stops a months-only answer from silently dropping up to 30 days.

What does the YD unit mean and when is it useful?

YD counts the days between the two dates as if they were in the same year - it ignores the year difference. June 1 to August 25 returns 85. It is useful for seasonal comparisons, like how far into a growing season, a school year or a sales cycle a date falls, where the years themselves do not matter.

Which DATEDIF units do I combine for an age in years, months and days?

Three of them: Y for the complete years, YM for the months left after those years, and MD for the days left after those months. The classic formula is =DATEDIF(A1,B1,"Y")&" years, "&DATEDIF(A1,B1,"YM")&" months, "&DATEDIF(A1,B1,"MD")&" days", which is how most age calculators built in Excel produce their answer.

Does the case of the unit matter, and do I need the quotation marks?

The case does not matter - "m" and "M" do the same job - but the quotation marks are required, because the unit is text. Leave them off and Excel or Sheets will treat the unit as a cell reference or a name and return an error instead of a count.

Related guides

How to calculate months between dates in Excel with DATEDIF

The formulas in context, with the two errors everyone hits.

How to calculate months between dates in Google Sheets

The same units in Sheets, plus a DATEDIF-free fallback formula.

How to convert months into years and days

Turning a single month count into the other units, both ways.

Common months-between mistakes - rounding and partial months

Wrong-unit answers and the other quiet errors, caught.

Daniel Mercer

Daniel Mercer builds and maintains the calculators on this site. He spent ten years in payroll and operations roles counting business days, notice periods and deadlines by hand, and writes these guides the way he would explain the count to a colleague - the rule first, a worked example second, and the common mistake called out before it happens.