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
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
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).
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | Name | Dept | Started | Born | Salary | Level | Age (years) | As of |
| 2 | Amara Osei | Sales | 15 Apr 2019 | 2 Aug 1990 | $58,000 | 2 | 35.91 | 30 Jun 2026 |
| 3 | Ben Fischer | Support | 9 Jan 2023 | 21 Nov 1996 | $41,000 | 1 | 29.60 | |
| 4 | Lina Chen | Engineering | 1 Sep 2016 | 14 Mar 1987 | $88,000 | 4 | 39.30 | |
| 5 | Diego Alvarez | Sales | 28 Jun 2021 | 30 Jun 1993 | $52,000 | 2 | 33.00 | |
| 6 | Eva Novak | Finance | 12 Feb 2018 | 5 Dec 1985 | $74,000 | 3 | 40.57 | |
| 7 | Farid Haddad | Engineering | 4 Mar 2024 | 19 Jan 1998 | $68,000 | 2 | 28.44 | |
| 8 | Grace Kim | Support | 19 Oct 2020 | 27 Sep 1991 | $45,000 | 2 | 34.76 | |
| 9 | Hugo Martin | Finance | 11 May 2015 | 8 Apr 1979 | $88,000 | 4 | 47.23 | |
| 10 | Ines Varga | Engineering | 14 Nov 2022 | 28 Feb 1995 | $79,000 | 3 | 31.33 | |
| 11 | Kenji Mori | Sales | 25 Aug 2025 | 16 Jul 2000 | $39,000 | 1 | 25.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. YEARFRAC: Gives the years between
D2and$H$2, with decimals.start=`D2`: the earlier dateend=`$H$2`: the later datebasis=`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
| Argument | Required | What it is |
|---|---|---|
| start_date | Yes | One of the two dates, usually the earlier one. |
| end_date | Yes | The other date, usually the later one, such as an "as of" date. |
| basis | No | How 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
INTor useDATEDIFwith "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
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.