YEARFRAC Function – Fraction of Year – Excel, VBA, G Sheets

Download Example Workbook

Download the example workbook

This tutorial demonstrates how to use the YEARFRAC Function in Excel, Google Sheets, and VBA to return the fraction of the year between dates.

YEARFRAC Main function

YEARFRAC Function Overview

The YEARFRAC Function Returns the fraction of a year between two dates.

To use the YEARFRAC function, select a cell and type:

yearfrac formula syntax

(Notice how the formula input appear)

YEARFRAC Function Syntax and Inputs:

=YEARFRAC(start_date,end_date,[basis])

start_date – The start date

end_date – The end date

[basis] – [Optional] The basis that determines the number of days in the year.

YEARFRAC Examples

Less Than One Year

=YEARFRAC(B3,C3)

Less Than One YearWhole Year

=YEARFRAC(B3,C3)

Whole YearMore than One Year

=YEARFRAC(B3,C3)

More than One Year

YEARFRAC Basis

By default, Excel uses the US 30/360 basis, where a year is 360 days long and each month has 30 days. Instead you can change the basis:

YEARFRAC Basis Table

Here is the impact of changing the basis:

Different Basis

YEARFRAC in Google Sheets

The YEARFRAC Function works exactly the same in Google Sheets as in Excel:
YEARFRAC Google Sheet

YEARFRAC Examples in VBA

You can also use the YEARFRAC function in VBA. Type:
application.worksheetfunction.yearfrac(start_date,end_date,basis)
For the function arguments (start_date, etc.), you can either enter them directly into the function, or define variables to use instead.