---
title: "5 ways to parse Dates and DateTimes in ClickHouse"
description: "ClickHouse offers five main routes for turning raw values into Date/DateTime types. `fromUnixTimestamp` and its 64Milli/64Micro variants convert epoch timestamps to `DateTime` or `DateTime64(3/6)`."
url: "https://swe.quest/articles/5-ways-to-parse-dates-and-datetimes-in-clickhouse-af81329ee4e38796"
canonical: "https://clickhouse.com/blog/parsing-dates-datetimes"
source: "ClickHouse"
published: "2026-03-12"
difficulty: "medium"
kind: "How-to"
reading_minutes: 4
tags: ["analytics","sql","time-clocks"]
---

# 5 ways to parse Dates and DateTimes in ClickHouse

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-03-12, 4 min read, How-to. Original: [https://clickhouse.com/blog/parsing-dates-datetimes](https://clickhouse.com/blog/parsing-dates-datetimes)

## Summary

ClickHouse offers five main routes for turning raw values into Date/DateTime types. \`fromUnixTimestamp\` and its 64Milli/64Micro variants convert epoch timestamps to \`DateTime\` or \`DateTime64(3/6)\`. \`YYYYMMDDToDate\` and \`YYYYMMDDhhmmssToDateTime\` handle packed numeric dates, and \`parseDateTime\` or \`parseDateTimeInJodaSyntax\` parse known format strings. For mixed or unknown formats, the \`parseDateTimeBestEffort\` family works, with OrNull and OrZero variants that avoid exceptions on invalid input. Plain \`::DateTime\` casts can also accept varied formats, including in queries over CSV files, once \`cast\_string\_to\_date\_time\_mode\` is set to \`best\_effort\` per query or per session.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Time & clocks](https://swe.quest/tags/time-clocks.md) (Distributed systems)

## Prerequisites

- basic SQL ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- ClickHouse basics ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

ClickHouse, parseDateTimeBestEffort, fromUnixTimestamp, DateTime64, cast\_string\_to\_date\_time\_mode, Joda

## Related posts

- [Querying DateTimes in ClickHouse](https://swe.quest/articles/querying-datetimes-in-clickhouse-2cdba42b9ef08c40.md): ClickHouse · 2026-03-20 · Medium · 8 min read · SQL, Analytics & OLAP, Time & clocks
  ClickHouse's datetime functions cover rounding, filtering and duration calculations, demonstrated on about 3 million NYC taxi trips. toStartOfHour and toStartOfFifteenMinutes bucket timestamps, casting to ::Time groups or filters by time of day across all dates, and dateDiff computes trip durations to derive average speed, which falls from about 19 mph at 6am to about 11 mph by 8:30am. countIf with toDayOfWeek splits weekday and weekend trips, and the lag window function computes percentage change between windows. formatDateTime and bar make the output readable.
- [Working with Time Series Data in ClickHouse](https://swe.quest/articles/working-with-time-series-data-in-clickhouse-d87ac55208de682a.md): ClickHouse · 2023-01-10 · Medium · 19 min read · Analytics & OLAP, SQL, Databases
  ClickHouse handles time-series workloads with Date, DateTime and DateTime64 types (up to nanosecond precision, with per-column timezones) plus SQL functions for bucketing by period. toStartOfHour and toStartOfInterval group by fixed or custom intervals, WITH FILL fills empty buckets, dateDiff builds offset rolling windows, and bar() gives quick inline visuals.
- [ClickHouse and the MTA Data Challenge](https://swe.quest/articles/clickhouse-and-the-mta-data-challenge-dc13e535ba1ed542.md): ClickHouse · 2024-10-24 · Medium · 16 min read · Analytics & OLAP, Data pipelines, SQL
  Loading and cleaning the ~95 million-row NYC MTA subway turnstile dataset (2014–2022) in ClickHouse, using schema inference over S3, a staging table, and an optimized schema with LowCardinality strings, a combined DateTime column, UInt32 counters, sorted line-name arrays and a (station, date\_time) ordering key.
- [What's New in pg\_clickhouse - JSONB Support, SQL value functions, Streaming, and more](https://swe.quest/articles/what-s-new-in-pg-clickhouse-jsonb-support-sql-value-functions-streaming-and-more-ecb202cf6ff32298.md): ClickHouse · 2026-04-24 · Medium · 10 min read · PostgreSQL, Analytics & OLAP, Query engines, Memory management
  pg\_clickhouse, the Postgres foreign data wrapper for querying ClickHouse, now pushes down far more operations to ClickHouse.
- [An Introduction to Data Formats in ClickHouse](https://swe.quest/articles/an-introduction-to-data-formats-in-clickhouse-9760492f888ea4b5.md): ClickHouse · 2023-01-24 · Medium · 6 min read · Analytics & OLAP, Data pipelines, Databases
  ClickHouse can import and export a wide range of formats through the FORMAT clause and related settings.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
