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?
Asked
Active
Viewed 5,261 times
2 Answers
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.

Ivan Blinkov
- 2,466
- 15
- 17
-
you can also use toFloat64 instead of toUInt64 - it will reveal fractional part of timestamp if it was inserted – lowtech Jun 28 '23 at 00:40
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 │
└────────────────────────────────────────────────────┘

Ilya
- 720
- 6
- 14