YEAR returns the year portion of a value.

Syntax

YEAR ( expression )

Arguments

expression: a DATE, TIMESTAMP, or non-LONG VARCHAR string value that is properly formatted to represent a DATE or TIMESTAMP.

Returns

  • An INTEGER. Returns NULL if expression is NULL.

Examples

SELECT orderDate, YEAR(orderDate) AS orderDateYear FROM MYSQL.inventory.cust;

VALUES YEAR(CAST('2019-06-20 15:23:45' AS TIMESTAMP))
-- Returns 2019