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 =YEARFRAC(A2,B2) returns 0.5000
Returns the time between two dates as a decimal number of years, using the day-count basis you choose.
Syntax
=YEARFRAC(, , )
All versions of Excel.
Try it
Edit the formula in C2 or change the inputs. The sheet recalculates as you type.
C2 =YEARFRAC(A2,B2) returns 0.5000
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 same two dates give different results depending on how days are counted. There are five day-count conventions:
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.
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.
=Principal*Rate*YEARFRAC(A2,B2,3).=Fee*YEARFRAC(A2,B2,1).=YEARFRAC(HireDate,TODAY(),1).=ROUND(YEARFRAC(A2,B2,1),2).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.
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!.Each example is a live sheet. Change the inputs or the formula and watch the result.
Example 1
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 =YEARFRAC(A2,B2) returns 0.5000
Example 2
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 =ROUND(YEARFRAC(A2,B2,3),4) returns 0.4959
Example 3
C2 =YEARFRAC(A2,B2)
Result: 2.50
Two full years plus six months is 2.5. DATEDIF with "y" would return 2.
C2 =YEARFRAC(A2,B2) returns 2.50
Example 4
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 =A2*B2*YEARFRAC(C2,D2) returns 300.00
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.
3 or 1.YEARFRAC(B2,A2) equals YEARFRAC(A2,B2), so a mistake in the order isn't visible.#NUM!, and a text date Excel can't read returns #VALUE!.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.
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.
DATEDIF counts complete years and drops the remainder. YEARFRAC returns a decimal, so it keeps the fractional part.
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.
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.