Spreadsheet Practice

Why does DATEDIF return #NUM!?

Formula (Excel and Google Sheets)

=DATEDIF(B2,IF(C2="",$G$1,C2),"y")

The start date is after the end date, usually because the end date is blank. Fill the gap: =DATEDIF(B2,IF(C2="",$G$1,C2),"y").

Result on the example
one result per row in D2, filled down to D7
Works in
Every current version
Google Sheets
Same formula

See it work

The formula is already in D2, filled down to D7. Change any input and the result updates, or edit the formula to experiment.

How it works

DATEDIF returns #NUM! when the start date is after the end date. A blank end date counts as 0, the earliest date there is, so every current employee errors. IF swaps in the as-of date when the end date is empty, so DATEDIF always gets a valid pair of dates.

=DATEDIF(B2,IF(C2="",$G$1,C2),"y")

Result8

  1. B23/12/2018

    The value in B2.

  2. C2(empty)

    The value in C2.

  3. C2=""TRUE

    The = operator tests whether the two sides are equal.

  4. $G$110/29/2026

    The value in G1.

  5. IF(C2="",$G$1,C2)46324

    IF: Returns one value if a test is true, another if false.

    • logical_testC2=""TRUE
    • value_if_true$G$110/29/2026
    • value_if_falseC2(empty)not used
  6. DATEDIF(B2,IF(C2="",$G$1,C2),"y")8

    DATEDIF: Difference in "Y", "M", "D", "YM", "MD" or "YD".

    • start_dateB23/12/2018
    • end_dateIF(C2="",$G$1,C2)46324
    • unit"y"

In Google Sheets

The same formula works in Google Sheets: =DATEDIF(B2,IF(C2="",$G$1,C2),"y"). We ran it in Google Sheets mode on the same data and it returns the same results.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=IF(C2="",DATEDIF(B2,$G$1,"y"),DATEDIF(B2,C2,"y"))8, 3, 1…The same choice, made outside DATEDIF.

Common mistakes

  • A start date later than a real end date also returns #NUM!. That is a data error worth fixing, not hiding.
  • The unit goes in quotes: "y", "m" or "d".
  • Put =TODAY() in G1 for tenure that updates every day.

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Why does DATEDIF return #NUM!

In D2, calculate whole years of service, using the date in G1 when there is no end date. Fill down to D7.

Questions

How do I show years and months?

=DATEDIF(B2,$G$1,"y")&" yrs "&DATEDIF(B2,$G$1,"ym")&" mos".

Why isn't DATEDIF in Excel's function list?

It is kept for compatibility and doesn't appear in autocomplete, but it works in every version and in Google Sheets.

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.