ClickHouse Functions/Date Functions

toDate

Convert a string or DateTime to a ClickHouse Date value.

Signature

toDate(value: String | DateTime | Int): Date

Returns

Date

What it does

Converts a string in YYYY-MM-DD format, a DateTime value, or a Unix timestamp integer to a ClickHouse Date. Used for date literals in WHERE clauses and INSERT statements.

toDate is the standard way to write date literals in ClickHouse SQL. When filtering by date ranges without a time component, toDate is cleaner than full DateTime literals. It also strips the time portion from a DateTime, which is useful when comparing a DateTime column against a Date value.

Notes

  • Accepted string format is YYYY-MM-DD only. Other formats require parseDateTimeBestEffort.
  • toDate(0) returns 1970-01-01 — useful for NULL-safe comparisons.
  • For DateTime64 columns, use toDate32 to preserve dates before 1970.

Example SQL

toDate in ClickHouse SQL

toDate-example.sql

TypeScript with hypequery

Use toDate in a typed TypeScript query

hypequery gives you a type-safe query builder for ClickHouse. The generated schema maps your ClickHouse columns to TypeScript types, and raw SQL expressions let you incorporate functions like toDate when you need them inside a builder query.

q1-events.ts

Common questions

What developers search for with toDate

ClickHouse date literal in WHERE clause

Use toDate('2024-01-01') to write date literals in ClickHouse SQL. Avoid string comparison — ClickHouse won't use the index correctly.

FAQ

Frequently asked questions about toDate

What string format does toDate accept?

'YYYY-MM-DD' only. For other formats use parseDateTimeBestEffort or formatDateTimeInJodaSyntax.

Related functions

Functions used alongside toDate

Next step

Use toDate in a type-safe TypeScript query

hypequery generates TypeScript types from your ClickHouse schema. Use toDate alongside the builder, and reach for raw SQL expressions when the function is not exposed as a dedicated helper.