# DATEDIF in Google Sheets: syntax and examples

URL: https://goingstellar.ro/reference/sheets/datedif/

DATEDIF returns the number of complete years, months or days between two dates, depending on the unit code. It is the usual way to calculate age or length of service.

## Syntax

```
DATEDIF(start_date, end_date, unit)
```

## Arguments

- `start_date` (date, required: yes): The earlier date.
- `end_date` (date, required: yes): The later date. If it is before start_date the result is #NUM!.
- `unit` (string, required: yes): Text code: "Y" years, "M" months, "D" days, "MD" days ignoring months and years, "YM" months ignoring years, "YD" days ignoring years.

## Examples

```
=DATEDIF(DATE(2024,1,15), DATE(2026,3,10), "Y")
```

Result: `2`

Complete years between 15 Jan 2024 and 10 Mar 2026. The second anniversary has passed, the third has not. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=DATEDIF(DATE(2024,1,15), DATE(2026,3,10), "M")
```

Result: `25`

Complete months in the same span. 10 Mar is before the 15th, so the 26th month is not complete. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=DATEDIF(DATE(2024,1,15), DATE(2026,3,10), "D")
```

Result: `785`

Total days between the two dates. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=DATEDIF(DATE(2024,1,15), DATE(2026,3,10), "YM")
```

Result: `1`

Months left over after full years: two years, then one month. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=DATEDIF(DATE(2000,5,20), DATE(2026,11,29), "Y")&" years"
```

Result: `26 years`

A typical age calculation, with text appended to the number. Run in a Google Sheet (English US locale) on 2026-11-29.

## Common errors

- If start_date is later than end_date, DATEDIF returns #NUM!. Swap the dates or wrap in IFERROR.
- The unit is text and must be quoted. A code that does not exist, such as "X", returns #NUM!.
- A value that is not a date, such as the text "abc", returns #VALUE!. Build dates with DATE instead of typing them as text.
- DATEDIF counts only complete periods. 25 months and 26 days is 25 months, with no rounding up.

## Compared with Excel

Same syntax as Excel DATEDIF. Microsoft documents the "MD" unit as unreliable.

## Questions and answers

### How do I show years and months together?

Join two calls: DATEDIF(a,b,"Y")&" years "&DATEDIF(a,b,"YM")&" months".

## Related functions

- [NETWORKDAYS](https://goingstellar.ro/reference/sheets/networkdays/)
- [EDATE](https://goingstellar.ro/reference/sheets/edate/)
- [TODAY](https://goingstellar.ro/reference/sheets/today/)

## Sources

- [DATEDIF (Docs Editors Help)](https://support.google.com/docs/answer/6055612)

