DateTime64 - how to use it?

979 views
Skip to first unread message

Michal Nowikowski

unread,
Dec 3, 2020, 12:46:33 AM12/3/20
to ClickHouse
Hello,

I'm trying to add data to column that has DateTime64 type.
What I'm getting is weird.
I'm using:
ClickHouse client version 20.11.4.13 (official build).
ClickHouse server version 20.11.4 revision 54442.

In the docs I find:
     When inserting datetime as an integer, it is treated as an appropriately scaled Unix
     Timestamp (UTC). 1546300800000 (with precision 3) represents '2019-01-01 00:00:00' UTC.

But in the client I get:
:) select toDateTime64(1546300800000, 3)
SELECT toDateTime64(1546300800000, 3)
Query id: 057bc596-653a-434d-a66a-19194d092f94
┌─toDateTime64(1546300800000, 3)─┐
│        1985-07-14 3$:00:00.000 │
└────────────────────────────────┘
1 rows in set. Elapsed: 0.004 sec.

This is 1985, not 2019.

What is wrong?

Regards,
Michal Nowikowski

Denis Zhuravlev

unread,
Dec 3, 2020, 9:18:40 AM12/3/20
to ClickHouse
DateTime64 is based on Decimal

1546300800000  ~ number of seconds NOT MILLISECONDS.

use Decimal style 1546300800.111 with dot

For inserts always use string form  '2019-01-01 00:00:00.000'

Denis Zhuravlev

unread,
Dec 3, 2020, 9:19:54 AM12/3/20
to ClickHouse

Michal Nowikowski

unread,
Dec 4, 2020, 12:49:24 AM12/4/20
to ClickHouse
Thanks for tips. I solved my problem.

Regards,
Michał
Reply all
Reply to author
Forward
0 new messages