v.20.5New Feature

New function toStartOfSecond for DateTime64 in ClickHouse

New function function toStartOfSecond(DateTime64) -> DateTime64 that nullifies sub-second part of DateTime64 value. #10722 (Vasily Nemkov).
Introduces the toStartOfSecond(DateTime64) function that truncates the sub-second part of a DateTime64 value, returning a DateTime64 truncated to whole seconds.

Why it matters

This feature addresses the need to normalize DateTime64 values by removing fractional seconds, which is useful for grouping, filtering, or comparing timestamps at the second level accuracy without sub-second details.

How to use it

Use the function in your queries by passing a DateTime64 column or value to toStartOfSecond. For example:

SELECT toStartOfSecond(your_datetime64_column) FROM your_table;