ClickHouse today Function

The today() function in ClickHouse returns the current date without the time component. It's commonly used when you need to work with the current date in queries, such as filtering records for the current day or calculating date-based metrics.

Syntax

today()

Official Documentation

Example usage

SELECT today() AS current_date;

SELECT * FROM events WHERE event_date = today();

Common issues

  • The today() function returns the date in the timezone of the server, which may not always match the user's local timezone.
  • It returns the same value within a query, even if the query runs past midnight.

Best practices

  • Use today() when you need the current date without time information.
  • For more precise timestamps including time, consider using now() instead.
  • Remember that today() is evaluated once per query execution, ensuring consistency across the entire query.

Frequently Asked Questions

Q: What's the difference between today() and now()?
A: today() returns only the current date, while now() returns the current date and time.

Q: Does today() consider timezones?
A: today() uses the server's timezone. To work with different timezones, you may need to use toDate(now()) with timezone conversions.

Q: Can I use today() in a WHERE clause?
A: Yes, it's common to use today() in WHERE clauses for filtering records related to the current date.

Q: How does today() behave in long-running queries?
A: today() is evaluated once at the start of the query execution and remains constant throughout, even if the query runs past midnight.

Q: Is there a performance impact when using today() frequently in queries?
A: today() is a lightweight function and generally doesn't have a significant performance impact. However, for very frequent calls, consider materializing its result into a variable.

Pulse - Elasticsearch Operations Done Right

Pulse can solve your Elasticsearch issues

Subscribe to the Pulse Newsletter

Get early access to new Pulse features, insightful blogs & exclusive events , webinars, and workshops.

We use cookies to provide an optimized user experience and understand our traffic. To learn more, read our use of cookies; otherwise, please choose 'Accept Cookies' to continue using our website.