Home / Companies / Tinybird / Blog / Post Details
Content Deep Dive

How to get the current timestamp with sub-second precision in ClickHouse ®

Blog post from Tinybird

Post Details
Company
Date Published
Author
Cameron Archer
Word Count
2,099
Language
English
Hacker News Points
-
Summary

The now64() function in ClickHouse® provides the capability to capture current timestamps with sub-second precision, supporting precision levels from seconds to nanoseconds, which is essential for applications requiring high-frequency event tracking and precise timing, such as performance measurement and real-time analytics. By returning timestamps as the DateTime64 data type, now64() allows users to customize the precision level, offering a balance between storage efficiency and temporal accuracy. This feature is particularly beneficial when dealing with high-frequency trading, scientific measurements, and distributed systems that need fine-grained event ordering. Implementation involves using appropriate syntax patterns, considering storage impacts, and ensuring effective timezone management to maintain consistency across different time zones. The article explores practical strategies for using now64() in production environments, including inserting and querying DateTime64 data, handling string-to-timestamp conversions, and leveraging Tinybird’s managed ClickHouse® platform to build high-precision, real-time analytics APIs.