跳转到内容

将日期或带时间的日期(timestamp/datetime)转换为包含年份(公元)的 UInt16 数字。

func.to_year(<expr>)
func.now(), func.to_year(func.now()), func.year(func.now())
┌───────────────────────────────────────────────────────────────────────────────┐
│ func.now() │ func.to_year(func.now()) │ func.year(func.now()) │
├────────────────────────────┼──────────────────────────┼───────────────────────┤
│ 2024-03-14 23:37:03.895166 │ 2024 │ 2024 │
└───────────────────────────────────────────────────────────────────────────────┘
TO_YEAR(<expr>)
参数 说明
<expr> date/timestamp

SMALLINT

SELECT NOW(), TO_YEAR(NOW()), YEAR(NOW());
┌───────────────────────────────────────────────────────────┐
│ now() │ to_year(now()) │ year(now()) │
├────────────────────────────┼────────────────┼─────────────┤
│ 2024-03-14 23:37:03.895166 │ 2024 │ 2024 │
└───────────────────────────────────────────────────────────┘