formulastreak

Dates function

YEARFRAC function in Google Sheets and Excel

YEARFRAC returns the years between two dates as a decimal, such as 7.21, using a day-count rule you choose.

Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet

Syntax

YEARFRAC(start_date, end_date, [basis])

Arguments in [brackets] are optional. Google Sheets writes it YEARFRAC(start_date, end_date, [day_count_convention]).

Example

=YEARFRAC(D2,$H$2,1) reads: Return the years from Amara's date of birth in D2 to the As of date in $H$2 as a decimal, counting actual days (basis 1).

Team directory · edit G2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultG2 = 35.91
ABCDEFGH
1NameDeptStartedBornSalaryLevelAge (years)As of
2Amara OseiSales15 Apr 20192 Aug 1990$58,000235.9130 Jun 2026
3Ben FischerSupport9 Jan 202321 Nov 1996$41,000129.60
4Lina ChenEngineering1 Sep 201614 Mar 1987$88,000439.30
5Diego AlvarezSales28 Jun 202130 Jun 1993$52,000233.00
6Eva NovakFinance12 Feb 20185 Dec 1985$74,000340.57
7Farid HaddadEngineering4 Mar 202419 Jan 1998$68,000228.44
8Grace KimSupport19 Oct 202027 Sep 1991$45,000234.76
9Hugo MartinFinance11 May 20158 Apr 1979$88,000447.23
10Ines VargaEngineering14 Nov 202228 Feb 1995$79,000331.33
11Kenji MoriSales25 Aug 202516 Jul 2000$39,000125.95

G2 shows 35.91: Amara's age in years with decimals, from 2 Aug 1990 to 30 Jun 2026.

How the spreadsheet calculates it

Gives the years between D2 and $H$2, with decimals.

  1. 1. YEARFRAC: Gives the years between D2 and $H$2, with decimals.
    • start = `D2`: the earlier date
    • end = `$H$2`: the later date
    • basis = `1`: how to count days

More YEARFRAC examples

  • =YEARFRAC(C2,$H$2,1)Years of service with decimals.
  • =INT(YEARFRAC(D2,$H$2,1))Age in whole years from a decimal age.
  • =YEARFRAC(DATE(2026,1,1),DATE(2026,7,1),1)*E2Half a year's share of the salary in E2.
  • =ROUND(YEARFRAC(C2,$H$2,1),1)Tenure rounded to one decimal, like 7.2.

Paste any of these into the formula explainer to see it step by step.

Tips

  • Always give the basis; leaving it out means the 30/360 rule, which surprises most people.
  • Format the cell with two decimals so the result reads like 7.21, not 7.2109589.
  • Multiply by an annual amount for pro-rata figures: YEARFRAC(start,end,1)*salary.

What YEARFRAC is used for

Pro-rata salary, bonus or holiday entitlement for part of a year, accrued interest between two dates, and ages or tenure with decimals for analysis.

Arguments

ArgumentRequiredWhat it is
start_dateYesOne of the two dates, usually the earlier one.
end_dateYesThe other date, usually the later one, such as an "as of" date.
basisNoHow days are counted: 0 or left out is US (NASD) 30/360, 1 actual/actual, 2 actual/360, 3 actual/365, 4 European 30/360.Watch out: A basis below 0 or above 4 gives #NUM!.

Common mistakes

  • Leaving out the basis and getting slightly different decimals from the 30/360 rule.

  • Expecting whole years: YEARFRAC gives decimals. Wrap it in INT or use DATEDIF with "Y" for completed years.

  • Comparing results from two workbooks that use different bases: the decimals differ slightly, so agree on one basis.

In Google Sheets

Google Sheets has YEARFRAC with the same three arguments; Google calls the third one day_count_convention and it's optional there too.

Errors you may see with YEARFRAC

  • #NUM!: basis is below 0 or above 4.
  • #VALUE!: start_date or end_date isn't a valid date.

Questions

Which basis should I use?

1 (actual/actual) for ages and tenure, because it uses the real length of each year. Finance teams sometimes need 0, 2, 3 or 4 to match a contract's day-count convention; check what yours says.

How do I get age with decimals in Excel?

YEARFRAC(birth, as_of, 1), formatted with two decimals. For Amara that's 35.91 years on 30 Jun 2026.

Why does YEARFRAC differ from days divided by 365?

Leap years: dividing by 365 drifts a little every four years, while basis 1 counts the actual days in each year.

Sources

Official documentation the facts on this page were checked against.

Practise YEARFRAC on a live sheet

Lesson 27, Years, months and tenure (Unit 7, Dates and time maths), has 5 graded exercises, checked instantly, with steps and hints when you're stuck. Pro