Investment Studio > Expressions > Functions > Date & Time > YEARFRAC

float yearfrac(date start_date, date end_date, integer day_count_basis = 0)

Returns the fraction of the year represented by the number of whole days between (and including) start_date and end_date.

Automatic type conversion allows the use of date strings as arguments instead of explicit date values.

The day_count_basis specifies how days are counted and the fraction computed:

day_count_basis Interpretation
0 US (NASD) 30/360: If start_date is the 31st of a month, it's set to the 30th of the same month. If end_date is the 31st of a month, it's set to the 30th of the same month unless start_date is less than the 30th of a month, in which case end_date is set to the 1st of the next month.

The denominator used to compute the fraction is 360.

1 Actual calendar days are counted and used to compute the fraction.
2 Actual calendar days are counted. The denominator used to compute the fraction is 360.
3 Actual calendar days are counted. The denominator used to compute the fraction is 365.
4 European 30/360: Start and end dates that occur on the 31st of a month are set to the 30th of the same month. The denominator used to compute the fraction is 360.

If day_count_basis is omitted, it defaults to 0 (NASD-style 360/30).

Note that the number of days between two dates in a calendar year can be obtained with plain subtraction of date values.

Example

Assuming standard US date format settings,

=yearfrac("01/01/2001", "06/30/2001", 0)

equals 0.497222222222222

=yearfrac("01/01/2000", "07/01/2000", 3)

equals 0.498630136986301.

See also days360, edate, eomonth, networkdays, workday.