DATEDIF function

Returns the number of time units (days, months, years) between two dates, useful for calculating durations, aging, or time-to-deadline.

=DATEDIF(start_date, end_date, unit)

Generate a DATEDIF formula

Describe what you need. The generator will reach for DATEDIF where DATEDIF is the right tool, and tell you when it is not.

How to get a better answer
  • Name your columns by letter and by header: "column F (Net Value)" beats "the amount column".
  • State every condition, including the negatives — "not cancelled" changes the formula's shape.
  • Say where the data starts if it is not row 1, and whether it will grow.
  • Check the settings above match your spreadsheet: the wrong argument separator is a syntax error on your machine.

Arguments

How DATEDIF reads its arguments
start_daterequiredend_daterequiredunitrequiredDATEDIF
ArgumentRequiredDescription
start_dateRequiredA date value marking the beginning of the period. Must be a valid date; if later than end_date, returns #NUM! error.
end_dateRequiredA date value marking the end of the period. Must be a valid date and on or after start_date.
unitRequiredA text code specifying the unit: 'D' (days), 'M' (months), 'Y' (years), 'MD' (day of month), 'YM' (month of year), 'YD' (day of year), or 'DM' (days excluding months). Invalid codes return #VALUE!.

Returns

A number representing the difference between two dates in the specified time unit.

Availability

Excel: All (undocumented) · Google Sheets: Supported

Worked examples

1. Days since an item was last ordered

SKULast Ordered
A0012026-08-15
=DATEDIF(B2, TODAY(), "D")

Result: 32

This calculates how many complete days have passed since the item was last ordered. With a start_date of August 15, 2026 and today's date (September 16, 2026), the result is 32 days. This tells you how recently stock was replenished and helps identify aging inventory that may need rotation or clearance.

2. Months remaining until the next inventory review

SKUNext Review
A0022026-12-01
=DATEDIF(TODAY(), B2, "M")

Result: 2

This counts the months remaining from today until the next review date of December 1, 2026. The result is 2 complete months. This helps track when inventory checks are due and plan ahead for potential restocking needs, audits, or data reconciliation activities.

3. Length of a reorder cycle in months

SKULast OrderedNext Review
A0022026-06-012026-12-01
=DATEDIF(B2, C2, "M")

Result: 6

This measures the length of the reorder cycle from the order date (June 1, 2026) to the next scheduled review (December 1, 2026). The result of 6 months shows the typical lead time and review interval for this item. Understanding cycle length helps predict future stock needs and optimize procurement schedules across warehouses.

Common errors

Which DATEDIF error are you seeing?
DATEDIF returned an error#NUM!
Reverse the date arguments so the earlier date comes first. Verify your date logic ensures the start date is chronologically before the end date.
#VALUE!
Use one of these valid unit codes: D (days), M (months), Y (years), MD (day of month), YM (month of year), YD (day of year), or DM (days excluding months).
#VALUE!
Use the DATE() function to create dates, or DATEVALUE() to convert text strings to actual date values before passing to DATEDIF.
ErrorWhy it happensHow to fix it
#NUM!DATEDIF is used with start_date later than end_date, such as =DATEDIF("2026-12-01", "2026-06-01", "M").Reverse the date arguments so the earlier date comes first. Verify your date logic ensures the start date is chronologically before the end date.
#VALUE!The unit code is not recognized, such as using 'Q', 'W', or 'H' instead of valid codes like 'D', 'M', or 'Y'.Use one of these valid unit codes: D (days), M (months), Y (years), MD (day of month), YM (month of year), YD (day of year), or DM (days excluding months).
#VALUE!Date arguments are text strings that cannot be interpreted as dates, such as when dates are imported from external sources without auto-conversion.Use the DATE() function to create dates, or DATEVALUE() to convert text strings to actual date values before passing to DATEDIF.

Tips and when to use something else

  • DATEDIF returns complete time units only, not partial ones. Between May 31 and June 1, unit 'M' returns 1 month, not a decimal amount.
  • Common unit codes: D=days, M=months, Y=years, MD=day-of-month, YM=month-of-year, YD=day-of-year. Older Excel versions may not support all codes; test for compatibility before deploying.
  • If you need start_date to be later than end_date, wrap DATEDIF in ABS() to return a positive number, or use DAYS() which handles date order automatically.
  • For working-day calculations between dates, use NETWORKDAYS() instead, as it excludes weekends and optional holidays—essential for supply-chain lead-time calculations.

Frequently asked questions

How do I calculate how many months until a deadline?
Use =DATEDIF(TODAY(), deadline_date, "M") to get the number of complete months. For example, with a deadline of December 1, 2026, this returns 2 if today is September 16, 2026. Remember that DATEDIF counts complete units, so a partial month doesn't increment the count.
What does MD mean in DATEDIF, and when would I use it?
MD returns only the day-of-month difference, ignoring years and months. For instance, =DATEDIF("2026-06-15", "2026-08-20", "MD") returns 5 because the difference between the 15th and 20th day is 5 days. This is useful for recurring monthly tasks or when tracking days within each month.
Can DATEDIF handle times, or only dates?
DATEDIF works with date-time values, but it only measures at the date level and ignores any time component. If you need hour or minute precision, subtract the cells directly (=end_datetime - start_datetime) and format the result as a duration, or divide by 24 to convert to hours.
Why am I getting an error when I use DATEDIF with my dates?
The most common cause is that start_date is after end_date (returns #NUM!), or the date values are stored as text rather than actual dates (returns #VALUE!). Use the DATE() function to create dates, or DATEVALUE() to convert text strings to proper date values for DATEDIF to work correctly.

Need a different formula?

The full generator is not scoped to one function — describe any spreadsheet problem and it will pick.

Open the formula generator

Reviewed 2026-09-17