Clickhouse: how to convert date to long integer?
Asked Answered
E

2

6

I have date as a string field in form of '2018-01-02 12:12:22', what is the right way to convert it to long int timestamp in ClickHouse SQL?

Equivocal answered 16/9, 2018 at 18:5 Comment(0)
C
7
:) SELECT toUInt64(toDateTime('2018-01-02 12:12:22'));

SELECT toUInt64(toDateTime('2018-01-02 12:12:22'))

┌─toUInt64(toDateTime('2018-01-02 12:12:22'))─┐
│                                  1514884342 │
└─────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.001 sec.
Crossland answered 17/9, 2018 at 6:53 Comment(1)
you can also use toFloat64 instead of toUInt64 - it will reveal fractional part of timestamp if it was insertedIdou
A
0

My query returns a different result

SELECT toUInt64(toDateTime('2018-01-02 12:12:22', 'UTC'))

┌─toUInt64(toDateTime('2018-01-02 12:12:22', 'UTC'))─┐
│                                         1514895142 │
└────────────────────────────────────────────────────┘
Aviary answered 9/9, 2020 at 14:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.