YEARFRAC
Returns the year fraction representing the number of whole days between the start date and end date.
Syntax
expression.YEARFRAC(arg1, arg2, arg3);
expression - A variable that represents a ApiWorksheetFunction class.
Parameters
| Name | Required/Optional | Data type | Default | Description |
|---|---|---|---|---|
| arg1 | Required | ApiRange | ApiName | number | A serial date number that represents the start date. | |
| arg2 | Required | ApiRange | ApiName | number | A serial date number that represents the end date. | |
| arg3 | Optional | ApiRange | ApiName | number | The type of day count basis to use: 0 or omitted - US (NASD) 30/360; 1 - Actual/actual; 2 - Actual/360; 3 - Actual/365; 4 - European 30/360. |
Returns
number
Example
Calculate the fraction of a year between two dates in a spreadsheet.
// How do I express the time period between two dates as a fraction of a year in a spreadsheet?
// Find the percentage of a year that spans between a start and end date in a spreadsheet.
const worksheet = Api.GetActiveSheet();
let func = Api.WorksheetFunction;
let ans = func.YEARFRAC("12/7/1981", "11/5/2018");
worksheet.GetRange("C1").SetValue(ans);