Tableau function Date

Tableau DATEPARSE to SQL

DATEPARSE(format, string) reads a string with an explicit format and returns a date-time, or null when the string doesn't match. The format uses ICU letters (yyyy, MM, dd, HH, mm, ss, MMMM); DuckDB's strptime uses percent codes (%Y, %m, %d, %H, %M, %S, %B). Use try_strptime so a bad string gives null, as in Tableau.

Updated · Checked on the xmetric engine

What is the syntax?

DATEPARSE(date_format, date_string)
date_format
a quoted ICU pattern such as 'dd/MM/yyyy'. It must match the string exactly.
date_string
the string to read.

Returns a date-time. Null if the string is null or doesn't match the format.

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.

How do I read day-first dates such as 29/12/2024?

Tableau

DATEPARSE('dd/MM/yyyy', [Local])

SQL (DuckDB)

SELECT try_strptime(Local, '%d/%m/%Y') AS result
FROM input
ORDER BY id

Rows 1 to 6 parse; "31/02/2025" is not a real day and "2 March 2025" is in another format, so both are null.

LocalResult
01/01/20212021-01-01 00:00
03/01/20212021-01-03 00:00
29/02/20242024-02-29 00:00
29/12/20242024-12-29 00:00
30/12/20242024-12-30 00:00
31/01/20252025-01-31 00:00
31/02/2025null
2 March 2025null
null

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

How do I read a spelled-out month such as 2 March 2025?

Tableau

DATEPARSE('d MMMM yyyy', [Local])

SQL (DuckDB)

SELECT try_strptime(Local, '%-d %B %Y') AS result
FROM input
ORDER BY id

MMMM is the full month name (%B), and a single d allows a one-digit day (%-d). Only row 8 matches.

LocalResult
01/01/2021null
03/01/2021null
29/02/2024null
29/12/2024null
30/12/2024null
31/01/2025null
31/02/2025null
2 March 20252025-03-02 00:00
null

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

Where does a straight translation go wrong?

Common mistake

Why does copying MM as %M put the month in the minutes?

In the ICU format MM is the month and mm the minute; in strptime %M is the minute and %m the month. A letter-for-letter copy reads 29/12/2024 as 29 January 2024, 00:12.

Tableau

DATEPARSE('dd/MM/yyyy', [Local])

Tempting SQL

SELECT try_strptime(Local, '%d/%M/%Y') AS result
FROM input
ORDER BY id

SQL that matches

SELECT try_strptime(Local, '%d/%m/%Y') AS result
FROM input
ORDER BY id
LocalTableauTempting SQLSQL that matches
01/01/20212021-01-01 00:002021-01-01 00:012021-01-01 00:00
03/01/20212021-01-03 00:002021-01-03 00:012021-01-03 00:00
29/02/20242024-02-29 00:002024-01-29 00:022024-02-29 00:00
29/12/20242024-12-29 00:002024-01-29 00:122024-12-29 00:00
30/12/20242024-12-30 00:002024-01-30 00:122024-12-30 00:00
31/01/20252025-01-31 00:002025-01-31 00:012025-01-31 00:00
31/02/2025null2025-01-31 00:02null
2 March 2025nullnullnull
nullnullnull

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 TRY_TO_TIMESTAMP(Local, 'DD/MM/YYYY') AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT SAFE.PARSE_DATETIME('%d/%m/%Y', Local) AS result
FROM input
ORDER BY id

BigQuery documentation

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

What does DATEPARSE return when the string doesn't match?

Null. "31/02/2025" (no such day) and "2 March 2025" (another format) return null with dd/MM/yyyy. strptime raises an error instead; try_strptime returns null.

How do I translate the format letters?

yyyy to %Y, MM to %m, dd to %d, HH to %H, mm to %M, ss to %S, MMM to %b, MMMM to %B, a to %p. Case matters on both sides.

Does DATEPARSE work on every connection?

No. Tableau's help lists the data sources it supports; it works in extracts. On others, convert in the database.

Where is this documented?