跳到主要内容

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

NameRequired/OptionalData typeDefaultDescription
arg1RequiredApiRange | ApiName | numberA serial date number that represents the start date.
arg2RequiredApiRange | ApiName | numberA serial date number that represents the end date.
arg3OptionalApiRange | ApiName | numberThe 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

const worksheet = Api.GetActiveSheet();

let func = Api.GetWorksheetFunction();
let ans = func.YEARFRAC("12/7/1981", "11/5/2018");

worksheet.GetRange("C1").SetValue(ans);