Skip to content

YEARFRAC

Returns the time between two dates as a decimal number of years, using the day-count basis you choose.

Syntax

=YEARFRAC(, , )

Date and time

All versions of Excel.

Try it

Edit the formula in C2 or change the inputs. The sheet recalculates as you type.

C2
A
B
C
1
Start
End
Years
2
01-Jan-2025
01-Jul-2025
0.5000
3

C2 =YEARFRAC(A2,B2) returns 0.5000

How YEARFRAC works

YEARFRAC returns the fraction of a year between two dates. From 1 January to 1 July is half a year, so =YEARFRAC(DATE(2025,1,1),DATE(2025,7,1)) returns 0.5. It is used for accrued interest, bond pricing, pro-rata fees, service length in decimal years, and any calculation that needs "how much of a year".

The basis decides the answer

The same two dates give different results depending on how days are counted. There are five day-count conventions:

  • 0, US (NASD) 30/360: every month is treated as 30 days and every year as 360. Whole months give tidy results: 1 January to 1 July is exactly 0.5. This is the default.
  • 1, actual/actual: actual days divided by the actual length of the year. For 1 January to 1 July 2025, that is 181 / 365 = 0.4959. Across several years it uses the average year length of the years spanned.
  • 2, actual/360: actual days over 360. It gives 181 / 360 = 0.5028 for the same dates and is common in money markets.
  • 3, actual/365: actual days over 365, 0.4959 for the same dates.
  • 4, European 30/360: like basis 0, but with European rules for dates on the 31st.

Agree the basis with whoever owns the contract or loan. A loan agreement may say "actual/365" and the default of 0 would then give the wrong interest.

YEARFRAC and DATEDIF

DATEDIF counts complete years, so a person aged 34 years and 8 months is 34. YEARFRAC returns the decimal, about 34.7. Use YEARFRAC when the fractional part matters. For an age in whole years, DATEDIF with "y" is the better fit, because rounding a YEARFRAC result can show a person as a year older the day before their birthday.

Common patterns

  • Simple interest between two dates: =Principal*Rate*YEARFRAC(A2,B2,3).
  • Pro-rata annual fee: =Fee*YEARFRAC(A2,B2,1).
  • Service in decimal years: =YEARFRAC(HireDate,TODAY(),1).
  • Rounded for display: =ROUND(YEARFRAC(A2,B2,1),2).

Order of the dates

YEARFRAC returns a positive number whichever date comes first. Unlike DATEDIF, it never returns a negative result or an error for reversed dates, so a swapped pair goes unnoticed.

The result is a plain number, not a date, so format it as a number. Time of day on either date is ignored.

Arguments

start_date
The first date. YEARFRAC doesn't mind which of the two dates is earlier: swapping them gives the same positive result.
end_date
The second date.
basisoptional
The day-count method. 0 or omitted: US 30/360. 1: actual days in the actual year. 2: actual days over a 360-day year. 3: actual days over a 365-day year. 4: European 30/360. Any other number returns #NUM!.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Half a year with the default 30/360 basis

C2 =YEARFRAC(A2,B2)

Result: 0.5000

Basis 0 treats each month as 30 days, so six months is 180 of 360 days: exactly 0.5.

C2
A
B
C
1
Start
End
Years
2
01-Jan-2025
01-Jul-2025
0.5000
3

C2 =YEARFRAC(A2,B2) returns 0.5000

Example 2

Actual days over 365 (basis 3)

C2 =ROUND(YEARFRAC(A2,B2,3),4)

Result: 0.4959

There are 181 days between the dates. 181 / 365 = 0.4959. The ROUND keeps the displayed answer short.

C2
A
B
C
1
Start
End
Years
2
01-Jan-2025
01-Jul-2025
0.4959
3

C2 =ROUND(YEARFRAC(A2,B2,3),4) returns 0.4959

Example 3

Service length in decimal years

C2 =YEARFRAC(A2,B2)

Result: 2.50

Two full years plus six months is 2.5. DATEDIF with "y" would return 2.

C2
A
B
C
1
Hire date
As of
Years of service
2
01-Jan-2022
01-Jul-2024
2.50
3

C2 =YEARFRAC(A2,B2) returns 2.50

Example 4

Simple interest for part of a year

E2 =A2*B2*YEARFRAC(C2,D2)

Result: 300.00

The period is exactly six months, which is 0.5 on the 30/360 basis. Interest is 10,000 x 6% x 0.5 = 300.

E2
A
B
C
D
E
1
Principal
Rate
From
To
Interest
2
10,000
6.0%
15-Jan-2025
15-Jul-2025
300.00
3

E2 =A2*B2*YEARFRAC(C2,D2) returns 300.00

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In C2, return the number of years between the two dates using the default 30/360 basis. Fill it down to C4.

Answer in C2, then it fills down to C4.

C2
A
B
C
D
E
F
1
Start
End
Years (30/360)
Years (actual/365)
2
01-Jan-2022
01-Jul-2024
3
01-Mar-2020
01-Mar-2025
4
15-Jun-2023
15-Dec-2023
5

Common mistakes

  • The default basis (0) is 30/360, not actual days. If a contract says actual/365 or actual/actual, pass 3 or 1.
  • Different bases give different answers for the same dates. Check which one your loan, bond or policy uses before you rely on the result.
  • Basis 1 across several years divides by the average length of the years spanned, so the result for a whole number of years can be slightly off a whole number.
  • Swapped dates don't cause an error or a negative result. YEARFRAC(B2,A2) equals YEARFRAC(A2,B2), so a mistake in the order isn't visible.
  • A basis outside 0 to 4 returns #NUM!, and a text date Excel can't read returns #VALUE!.

Questions people ask

How do I calculate decimal years between two dates?

Use `=YEARFRAC(A2,B2,1)` for actual days over the actual year, or `=YEARFRAC(A2,B2)` for the 30/360 default. Round the result for display with ROUND.

Which basis should I use?

The one your contract specifies. For general reporting of elapsed time, basis 1 (actual/actual) is the most natural. For loans quoted on 30/360, use 0.

What is the difference between YEARFRAC and DATEDIF?

DATEDIF counts complete years and drops the remainder. YEARFRAC returns a decimal, so it keeps the fractional part.

Why does YEARFRAC give 0.4959 instead of 0.5?

You are on a basis that uses actual days, such as 1 or 3. Six months is 181 days in 2025, and 181 / 365 is 0.4959. The default basis 0 treats the same period as exactly 0.5.

Learn YEARFRAC in a real sheet.

YEARFRAC is taught in Dates and financial modelling, lesson 8: Tenure and age with DATEDIF and YEARFRAC. Each lesson is a short, graded exercise like the one above.