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

How to extract ISO week numbers from dates in ClickHouse ®

Blog post from Tinybird

Post Details
Company
Date Published
Author
Cameron Archer
Word Count
2,632
Company Posts That Month
81
Language
English
Hacker News Points
-
Post removed?
No
Summary

ISO week numbers are crucial for consistent analytics across year boundaries, avoiding partial-week aggregates in reporting. The toISOWeek() function in ClickHouse®, adhering to ISO 8601 standards, starts weeks on Monday, with week 1 containing January 4th. This can lead to counterintuitive results, such as December 31st being part of week 1 of the following year, which can confuse developers working with time-based analytics. The function, available since ClickHouse® version 19.15, takes a date or datetime value and returns a week number between 1 and 53. It supports various data types and automatically handles time zones. Developers can use it alongside toISOYear() for comprehensive year-week analysis, especially important around year boundaries. The guide provides strategies for optimizing performance, such as using materialized columns and secondary indexes, and explains how to build robust analytics APIs using Tinybird's managed ClickHouse® platform, which simplifies infrastructure management and ensures consistent ISO week calculations across regions and time zones.

Trends Found in this Post
Trend Post Mentions Total Month Mentions Posts Companies MoM
Real-time 2 6,551 1,245 236 +61%
Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.