跳到主要内容

YEAR

返回日期的年份,范围为 1900-9999 的整数。

语法

expression.YEAR(arg1);

expression - 表示 ApiWorksheetFunction 类的变量。

参数

名称必需/可选数据类型默认值描述
arg1必需ApiRange | ApiName | number日期时间代码中的数字,或其他公式或函数的结果。

返回值

number

示例

从电子表格中的日期值提取年份。

// How do I get the year portion of a date in a spreadsheet?

// Retrieve the four-digit year number from any date in a spreadsheet.

const worksheet = Api.GetActiveSheet();

let func = Api.WorksheetFunction;
let ans = func.YEAR("3/16/2018");

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