跳转到内容

将日期或带时间的日期(timestamp/datetime)转换为包含月份编号(1-12)的 UInt8 数字。

func.to_month(<expr>)
func.now(), func.to_month(func.now()), func.month(func.now())
┌─────────────────────────────────────────────────────────────────────────────────┐
│ func.now() │ func.to_month(func.now()) │ func.month(func.now()) │
├────────────────────────────┼───────────────────────────┼────────────────────────┤
│ 2024-03-14 23:34:02.161291 │ 3 │ 3 │
└─────────────────────────────────────────────────────────────────────────────────┘
TO_MONTH(<expr>)
参数 说明
<expr> 日期/时间戳

TINYINT

SELECT NOW(), TO_MONTH(NOW()), MONTH(NOW());
┌─────────────────────────────────────────────────────────────┐
│ now() │ to_month(now()) │ month(now()) │
├────────────────────────────┼─────────────────┼──────────────┤
│ 2024-03-14 23:34:02.161291 │ 3 │ 3 │
└─────────────────────────────────────────────────────────────┘