YEAR
Returns the year of a date, an integer in the range 1900-9999.
Syntax
expression.YEAR(arg1);
expression - A variable that represents a ApiWorksheetFunction class.
Parameters
| Name | Required/Optional | Data type | Default | Description |
|---|---|---|---|---|
| arg1 | Required | ApiRange | ApiName | number | A number in the date-time code, or a result of other formulas or functions. |
Returns
number
Example
Extract the year from a date value in a spreadsheet.
// 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);