Groups
Groups
Sign in
Groups
Groups
ClickHouse: https://clickhouse.com/slack
Conversations
Labels
About
Send feedback
Help
Time rounding to different intervals
790 views
Skip to first unread message
Saptarshi Gan
unread,
Dec 4, 2017, 9:31:17 AM
12/4/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ClickHouse
Like
toStartOfMinute
toStartOfHour
is it possible to round up the date time to any random interval? Like to Start of 2 minute or to Start of 10 minute!
Saptarshi Gan
unread,
Dec 4, 2017, 9:44:14 AM
12/4/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ClickHouse
Is there a way to convert datetime to unix timestamp?
Saptarshi Gan
unread,
Dec 4, 2017, 10:17:03 AM
12/4/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ClickHouse
Multiple CASTS would do the trick I guess!
CAST(floor(CAST(timestamp AS UInt64)/300)*300 AS DateTime)
Alex Zatelepin
unread,
Dec 4, 2017, 11:29:56 AM
12/4/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ClickHouse
You can use functions toUnixTimestamp and intDiv for this task - that will be slightly more efficient. Your query becomes:
toDateTime
(
intDiv
(
toUnixTimestamp
(
timestamp
),
300
)
*
300
)
(BTW there is a function toStartOfFiveMinute specifically for 300 seconds)
Reply all
Reply to author
Forward
0 new messages