
Excel stores dates as numbers: 1 January 1900 is 1 and every day adds one. That is why subtracting one date from another gives the number of days between them. Months, years and working days need dedicated functions.
Days between two dates
With the start date in A2 and the end date in B2:
=B2-A2If the result looks like a date, set the cell format to General or Number. The equivalent function is =DAYS(B2,A2). Add 1 if both the start and end day should count.
Days elapsed until today: =TODAY()-A2
Months and years: DATEDIF
DATEDIF does not appear in Excel's formula suggestions, but it works in every version:
=DATEDIF(A2,B2,"Y") complete years
=DATEDIF(A2,B2,"M") complete months
=DATEDIF(A2,B2,"D") days
=DATEDIF(A2,B2,"YM") months left after whole years
=DATEDIF(A2,B2,"MD") days left after whole monthsIf the start date is later than the end date, it returns #NUM!.
Age and length of service
With a date of birth in A2, the current age is:
=DATEDIF(A2,TODAY(),"Y")For service in the form "5 years 3 months 12 days":
=DATEDIF(A2,TODAY(),"Y")&" years "&DATEDIF(A2,TODAY(),"YM")&" months "&DATEDIF(A2,TODAY(),"MD")&" days"For a decimal number of years (for example 5.27), use =YEARFRAC(A2,TODAY()).
Working days: NETWORKDAYS
Count working days between two dates, excluding weekends:
=NETWORKDAYS(A2,B2)To exclude public holidays too, list them in a range (for example Holidays!A2:A20) and pass it as the third argument:
=NETWORKDAYS(A2,B2,Holidays!$A$2:$A$20)If your week is different, use NETWORKDAYS.INTL. Weekend code 11 treats only Sunday as a day off: =NETWORKDAYS.INTL(A2,B2,11,Holidays!$A$2:$A$20).
Calculating future dates
| Need | Formula |
|---|---|
| 30 days later | =A2+30 |
| 10 working days later | =WORKDAY(A2,10,Holidays!$A$2:$A$20) |
| 3 months later (due date) | =EDATE(A2,3) |
| Last day of the month | =EOMONTH(A2,0) |
| Days overdue (or 0) | =MAX(0,TODAY()-B2) |
When EDATE adds a month to 31 January, it returns the last day of February. For due dates that is usually what you want.
Common mistakes
- Dates stored as text: if a date is left-aligned, Excel does not see it as a date. Data > Text to Columns > Finish or
=DATEVALUE(A2)usually fixes it. - Day and month swapped: in files from other countries, 03/04 can mean 3 April or 4 March. When in doubt, rebuild the date with
=DATE(year,month,day). - Times included: with date-time values the difference has decimals. Use
=INT(B2)-INT(A2)for whole days.
Step-by-step example: showing an employee's tenure in years, months and days
Suppose the start date is in A2 and the calculation date (today) in B2:
| Cell | Formula | Meaning |
|---|---|---|
| C2 (years) | =DATEDIF(A2,B2,"Y") | Complete years |
| D2 (months) | =DATEDIF(A2,B2,"YM") | Remaining months excluding years |
| E2 (days) | =DATEDIF(A2,B2,"MD") | Remaining days excluding months |
| F2 (text) | =C2&" years "&D2&" months "&E2&" days" | "3 years 4 months 12 days" |
| G2 (total days) | =B2-A2 | Total number of days |
DATEDIF is a hidden function; it may not appear in the function wizard but works if you type it. If the start date is after the end it gives a #NUM! error. In some versions and regions the "MD" result can be unreliable; for critical calculations check the result or build an alternative. For language and version differences look at the local name of the function.
Which measure with which formula between two dates?
| Need | Formula |
|---|---|
| Calendar days | =B2-A2 |
| Working days | =NETWORKDAYS(A2,B2) (see our working days guide) |
| Complete months | =DATEDIF(A2,B2,"M") |
| Fraction of a year | =YEARFRAC(A2,B2) |
| Number of weeks | =INT((B2-A2)/7) |
| Age | =DATEDIF(A2,TODAY(),"Y") |
Time difference
For dates containing times the difference comes as a fraction of a day: =(B2-A2)*24 gives hours. To show the result as [h]:mm use a custom format. For shifts that cross midnight =MOD(B2-A2,1) avoids negative results.
Frequently asked questions
Why does the result look like a date? The difference cell has a date format; switch it to General or Number.
What happens when dates are text? The difference gives #VALUE!; convert with DATEVALUE (see our date functions and data cleaning guides).
How many days until my birthday? Find this year's birthday with =DATE(YEAR(TODAY()),MONTH(A2),DAY(A2)); if it has passed add a year and subtract TODAY().
Do leap years affect the calculation? The day difference is calculated by the real calendar; for fraction of a year you can pick the day basis with YEARFRAC.
Which suits a project duration? Show both working days and calendar days (for a project timeline see our Gantt guide).
Serkan Akyürek is the founder and author of toolrota; he writes step-by-step guides on Excel, AI, the cloud, personal finance and digital security.