Skip to main content

TO_YYYYMMDDHH

Formats a given date or timestamp into a string representation in the format "YYYYMMDDHH" (Year, Month, Day, Hour).

Syntax​

TO_YYYYMMDDHH(<expr>)

Arguments​

ArgumentsDescription
<expr>date/datetime,date as default

Return Type​

Returns an unsigned 64-bit integer (UInt64) in the format "YYYYMMDDHH".

Examples​

SELECT to_yyyymmddhh('2023-11-12 09:38:18.165575'), to_yyyymmddhh(to_date('2023-11-12 09:38:18.165575'));
┌─────────────────────────────────────────────┐─────────────────────────────────────────────────────┐
│ to_yyyymmddhh('2023-11-12 09:38:18.165575') │to_yyyymmddhh(to_date('2023-11-12 09:38:18.165575') │
│ UInt32 │ UInt32 │
├─────────────────────────────────────────────┤─────────────────────────────────────────────────────┤
│ 2023111200 │ 2023111200 │
└─────────────────────────────────────────────┘─────────────────────────────────────────────────────┘

SELECT to_yyyymmddhh(to_timestamp('2023-11-12 09:38:18.165575'));

┌───────────────────────────────────────────────────────────┐
│ to_yyyymmddhh(to_timestamp('2023-11-12 09:38:18.165575')) │
│ UInt32 │
├───────────────────────────────────────────────────────────┤
│ 2023111209 │
└───────────────────────────────────────────────────────────┘

Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today