Tableau function Date

Tableau NOW to SQL

NOW() returns the current local date and time as a date-time, and takes no argument. In DuckDB the match is now() (or current_timestamp), which is a timestamp with time zone: cast it to TIMESTAMP before comparing it with a plain timestamp column. The examples below compare against NOW instead of showing it, so their results don't change from day to day.

Updated · Checked on the xmetric engine

What is the syntax?

NOW()

Returns a date-time: the current local date and time.

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 placed before this moment?

Tableau

[Ordered] < NOW()

SQL (DuckDB)

SELECT Ordered < CAST (now() AS TIMESTAMP) AS result
FROM input
ORDER BY id

Every sample order is in the past, so the answer stays true; the blank row stays null. Without the cast, DuckDB compares a timestamp with a timestamp with time zone.

OrderedResult
2021-01-01 08:00true
2021-01-03 18:45true
2024-02-29 10:15true
2024-12-29 16:25:40true
2024-12-30 09:05true
2025-01-31 23:59:59true
2025-03-01 00:00true
2025-03-02 12:30:15true
null

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

Is NOW on the same day as TODAY?

Tableau

DATEDIFF('day', TODAY(), NOW())

SQL (DuckDB)

SELECT
  date_diff('day', current_date, CAST (now() AS TIMESTAMP)) AS result
FROM input
ORDER BY id

Zero days apart: NOW is today's date with the current time added.

Result
0
0
0
0
0
0
0
0
0

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

Where does a straight translation go wrong?

Common mistake

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

now() carries the time of day, so comparing it with current_date (midnight) is false all day except at the exact stroke of midnight. Truncate it to the day first, as DATETRUNC('day', NOW()) does.

Tableau

DATETRUNC('day', NOW()) = TODAY()

Tempting SQL

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

SQL that matches

SELECT
  date_trunc('day', CAST (now() AS TIMESTAMP)) = current_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 Ordered < CURRENT_TIMESTAMP() AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT Ordered < CURRENT_DATETIME() AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own NOW 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 NOW?

Whose clock does NOW read?

Tableau's help says it is the local system time; on a live connection that can be the database server's time, in another time zone. DuckDB's now() uses the session's TimeZone setting.

Does NOW change between rows?

No. It is evaluated once per query, so every row sees the same value. The same holds for now() in DuckDB, which is fixed at the start of the transaction.

Should I use NOW or TODAY?

Use TODAY when you compare dates and NOW when the time of day matters. [Due] < TODAY() means "due before today"; [Ordered] < NOW() means "placed before this second".

Where is this documented?