# DATEDIF formula generator

> Describe what you need and get a DATEDIF formula for Excel and Google Sheets, run on real data before you copy it. Plus 8 tested DATEDIF examples.

Source: https://spreadsheetpractice.com/tools/formula-generator/datedif · Updated October 29, 2026 · Formulas and results on this page were run by the Spreadsheet Practice formula engine on November 20, 2026

DATEDIF counts the complete years, months or days between two dates.

Describe the task at [DATEDIF formula generator](https://spreadsheetpractice.com/tools/formula-generator/datedif) and get a DATEDIF formula for Excel and Google Sheets, tested on real data.

## Tested DATEDIF examples

### Calculate the number of months between two dates

`=DATEDIF(B2,C2,"m")`

Excel. Result on the sample sheet: 5 rows (D2:D6). [See it and try it](https://spreadsheetpractice.com/formulas/months-between-two-dates)

### Calculate age from a date of birth

`=DATEDIF(B2,$F$1,"y")`

Excel. Result on the sample sheet: 5 rows (C2:C6). [See it and try it](https://spreadsheetpractice.com/formulas/calculate-age-from-date-of-birth)

### Calculate years of service

`=DATEDIF(B2,$F$1,"y")&" years, "&DATEDIF(B2,$F$1,"ym")&" months"`

Excel. Result on the sample sheet: 5 rows (C2:C6). [See it and try it](https://spreadsheetpractice.com/formulas/years-of-service)

### Why does DATEDIF return #NUM!

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

Excel. Result on the sample sheet: 6 rows (D2:D7). [See it and try it](https://spreadsheetpractice.com/formulas/datedif-num-error)

### Check if someone is over 18 from their date of birth

`=IF(DATEDIF(B2,$F$1,"y")>=18,"Yes","No")`

Excel. Result on the sample sheet: 6 rows (C2:C7). [See it and try it](https://spreadsheetpractice.com/formulas/check-if-over-18-from-date-of-birth)

## Questions

### What does the DATEDIF formula generator do?

You describe the task in plain English, and it writes the formula, using DATEDIF where that's the right tool, for your table or a sample one. The formula is run in our engine in Excel and Google Sheets mode before you see it, so you get its result, not just a guess.

### What does DATEDIF do?

DATEDIF counts the complete years, months or days between two dates.

### Can I learn to write DATEDIF formulas myself?

Yes. Each example below opens a page where you try the formula in a live grid and it's checked as you go, and the DATEDIF function page has a practice exercise.

---

Spreadsheet Practice (https://spreadsheetpractice.com) teaches spreadsheet formulas by practice: every exercise is graded in a live grid and re-checked on changed data.
