Tableau function Date

Tableau TODAY to SQL

TODAY() returns the current local date, with no time of day, and takes no argument. In DuckDB the match is current_date. Compare it with dates, not with now(): a date and a date-time are equal only at midnight. The examples compare against TODAY instead of showing it, so their results don't change from day to day.

Updated · Checked on the xmetric engine

What is the syntax?

TODAY()

Returns a date: the current local date.

What does it return, and what is the SQL?

Each example runs on the same 9 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.

Was each order due before today?

Tableau

[Due] < TODAY()

SQL (DuckDB)

SELECT Due < current_date AS result
FROM input
ORDER BY id

Every sample due date is in the past, so the answer stays true; the blank row stays null.

DueResult
2021-01-01true
2021-01-03true
2024-02-29true
2024-12-29true
2024-12-30true
2025-01-31true
2025-03-01true
2025-03-02true
null

The Tableau formula and the SQL return the same 9 rows.

Is midnight tomorrow always later than now?

Tableau

DATEADD('day', 1, TODAY()) > NOW()

SQL (DuckDB)

SELECT
  current_date
    + INTERVAL 1 DAY > CAST (now() AS TIMESTAMP) AS result
FROM input
ORDER BY id

Adding a day to TODAY gives the start of tomorrow, the usual upper bound for "today" filters: [Ordered] >= TODAY() AND [Ordered] < DATEADD('day', 1, TODAY()).

Result
true
true
true
true
true
true
true
true
true

The Tableau formula and the SQL return the same 9 rows.

Where does a straight translation go wrong?

Common mistake

Why is today's date never equal to now()?

TODAY is a date, which compares as midnight. now() has the time of day, so current_date = now() is false almost all day. Cast now() to a date, as DATE(NOW()) does.

Tableau

TODAY() = DATE(NOW())

Tempting SQL

SELECT current_date = CAST (now() AS TIMESTAMP) AS result
FROM input
ORDER BY id

SQL that matches

SELECT current_date = CAST (now() AS DATE) AS result
FROM input
ORDER BY id
TableauTempting SQLSQL that matches
truefalsetrue
truefalsetrue
truefalsetrue
truefalsetrue
truefalsetrue
truefalsetrue
truefalsetrue
truefalsetrue
truefalsetrue

The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.

How do I write it in Snowflake or BigQuery?

The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.

Snowflake

SELECT Due < CURRENT_DATE() AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT Due < CURRENT_DATE() AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own TODAY formula return?

Edit the formula and run it on the 9 sample rows. Fields: [id], [Ordered], [Due], [Text], [Local], [Y], [M], [D].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about TODAY?

How do I keep the last 30 days?

[Due] >= DATEADD('day', -30, TODAY()); in SQL Due >= current_date - INTERVAL 30 DAY.

Whose date is TODAY?

The local system date. Tableau's help notes that on a live connection the system date may be in another time zone; DuckDB's current_date follows the session's TimeZone setting.

How is TODAY different from NOW?

TODAY is a date (midnight); NOW is a date-time with the current time. DATE(NOW()) equals TODAY().

Where is this documented?