New Tool Radar

AI for Data & Spreadsheets

How to Check Whether an AI-Written DATEDIF Formula Returns Age or Tenure in the Right Unit

Check whether an AI-written DATEDIF formula returns age or tenure in the intended unit, years, months or days.

Schematic with three steps: Read the unit argument; Work out the answer by hand in; Fix the unit and re-check.

DATEDIF returns the difference between two dates in a unit chosen by its third argument: “Y” for whole years, “M” for whole months, “D” for days, and “YM” or “MD” for the leftover months or days. An AI-written formula that uses “D” when the reader wanted years returns a number in the thousands, and one that uses “Y” when the reader wanted months returns a small number that looks wrong. Read the unit argument before trusting the number.

What you need

  • The AI-written DATEDIF formula
  • The two dates it compares
  • The unit the reader wants: years, months or days

Step 1: Read the unit argument

Click the formula cell and read the third argument in quotes. “Y” gives whole years, “M” gives whole months, and “D” gives days.

Step 2: Work out the answer by hand in the intended unit

Count the whole years, months or days between the two dates by hand and write the number down. A tenure of 3 years and 4 months is 3 in “Y” and 40 in “M”.

Step 3: Fix the unit and re-check

Change the unit argument to the intended one and compare the result with the hand count. If the answer needs years and leftover months, use two DATEDIF calls, one with “Y” and one with “YM”.

Worked example: synthetic tenure from 2019 to 2026

The table below is a synthetic example. It shows the expected result of checking an AI-written DATEDIF formula; no formula was run.

Check Value Result
Start date 2019-06-15 Joined
End date 2026-06-15 Seven years later
Unit as written “D” Returns 2,557 days
Corrected unit “Y” Returns 7 years

Expected result (UNTESTED). DATEDIF with unit “D” returns 2,557 days between 2019-06-15 and 2026-06-15, but the reader wanted years; changing the unit to “Y” returns 7, matching the hand count. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • DATEDIF is undocumented and returns #NUM! when the start date is after the end date.
  • The “MD” unit can give a misleading day count near month ends, so prefer “Y” and “YM” for age and tenure.
  • DATEDIF counts whole units only, so 11 months and 29 days is 0 in “Y”.
  • A start date stored as text must be converted with DATEVALUE before DATEDIF can use it.

Sources

See all