跳转到主要内容

TO_YEAR

Converts a date or date with time (timestamp/datetime) to a UInt16 number containing the year number (AD).

Syntax

to_year( <expr> )

Arguments

ArgumentsDescription
<expr>date/timestamp

Return Type

A UInt16 date type value

Examples

SELECT to_year(now());
+----------------+
| to_year(now()) |
+------- --------+
| 2022 |
+----------------+

SELECT to_year(to_timestamp(1));
+--------------------------+
| to_year(to_timestamp(1)) |
+--------------------------+
| 1970 |
+--------------------------+