How to Get Current Date in ClickHouse

Galaxy Glossary

How do I get today’s date in ClickHouse?

today() and currentDate() return the server’s current date as a Date value in ClickHouse.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Table of Contents

What does today() do in ClickHouse?

today() returns the server’s current date as a Date type, identical to the value of currentDate(). It is the ClickHouse equivalent of PostgreSQL’s CURRENT_DATE, but follows the server time zone rather than the client’s.

How do I get today’s date in ClickHouse?

Run a simple SELECT statement. Both functions are argument-free and available in every ClickHouse build.

SELECT today() AS current_date;
SELECT currentDate() AS current_date;

Can I filter records by the current date?

Yes. Cast your DateTime column to Date, then compare it to today() to avoid mismatched types.

SELECT *
FROM Orders
WHERE toDate(order_date) = today();

What is the full syntax of today()?

today() → Date   •   currentDate() → Date   •   toDate(now()) → Date

Best practices for using the current date

Prefer today() for date-only comparisons. Use now() when you need a full timestamp. Store data in UTC and remember that today() respects the server time zone, not the client’s.

Common mistakes and how to fix them

Comparing DateTime directly to today()

The comparison fails because DateTime ≠ Date. Fix by casting: toDate(created_at) = today().

Assuming today() uses the client time zone

today() follows the server’s zone. Set the session time zone or convert values to UTC to avoid surprises.

FAQ

Is CURRENT_DATE supported in ClickHouse?

No. Use today() or currentDate(). CURRENT_DATE is parsed as an identifier and triggers a syntax error.

How do I get yesterday’s date?

Call yesterday(), or use subtractDays(today(), 1).

Can I set a default column value to today()?

Yes—define the column as created_on Date DEFAULT today().

Why How to Get Current Date in ClickHouse is important

How to Get Current Date in ClickHouse Example Usage


-- Customers who placed an order today
SELECT c.id,
       c.name,
       SUM(oi.quantity)      AS items_bought,
       SUM(oi.quantity*p.price) AS amount_spent
FROM Customers   AS c
JOIN Orders      AS o  ON o.customer_id = c.id
JOIN OrderItems  AS oi ON oi.order_id     = o.id
JOIN Products    AS p  ON p.id            = oi.product_id
WHERE toDate(o.order_date) = today()
GROUP BY c.id, c.name;

How to Get Current Date in ClickHouse Syntax


-- Return today’s date
SELECT today();
SELECT currentDate();

-- Alias the result
SELECT today() AS current_date;

-- Filter ecommerce tables
SELECT *
FROM Orders
WHERE toDate(order_date) = today();

-- Join example
SELECT c.id,
       c.name,
       COUNT(o.id) AS orders_today
FROM Customers AS c
LEFT JOIN Orders AS o
       ON o.customer_id = c.id
WHERE toDate(o.order_date) = today()
GROUP BY c.id, c.name;

Common Mistakes

Frequently Asked Questions (FAQs)

Does ClickHouse support CURRENT_DATE?

No. Use today() or currentDate().

How can I get yesterday or tomorrow?

Use yesterday(), tomorrow(), or subtractDays()/addDays() around today().

Can I use today() in materialized views?

Yes, but remember it evaluates at INSERT time, not SELECT time.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.