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)
SELECTtry_strptime(Local, '%d/%m/%Y') AS result
FROM input
ORDERBY 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.
Local
Result
01/01/2021
2021-01-0100:00
03/01/2021
2021-01-0300:00
29/02/2024
2024-02-2900:00
29/12/2024
2024-12-2900:00
30/12/2024
2024-12-3000:00
31/01/2025
2025-01-3100:00
31/02/2025
null
2 March 2025
null
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)
SELECTtry_strptime(Local, '%-d %B %Y') AS result
FROM input
ORDERBY id
MMMM is the full month name (%B), and a single d allows a one-digit day (%-d). Only row 8 matches.
Local
Result
01/01/2021
null
03/01/2021
null
29/02/2024
null
29/12/2024
null
30/12/2024
null
31/01/2025
null
31/02/2025
null
2 March 2025
2025-03-0200: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
SELECTtry_strptime(Local, '%d/%M/%Y') AS result
FROM input
ORDERBY id
SQL that matches
SELECTtry_strptime(Local, '%d/%m/%Y') AS result
FROM input
ORDERBY id
Local
Tableau
Tempting SQL
SQL that matches
01/01/2021
2021-01-0100:00
2021-01-0100:01
2021-01-0100:00
03/01/2021
2021-01-0300:00
2021-01-0300:01
2021-01-0300:00
29/02/2024
2024-02-2900:00
2024-01-2900:02
2024-02-2900:00
29/12/2024
2024-12-2900:00
2024-01-2900:12
2024-12-2900:00
30/12/2024
2024-12-3000:00
2024-01-3000:12
2024-12-3000:00
31/01/2025
2025-01-3100:00
2025-01-3100:01
2025-01-3100:00
31/02/2025
null
2025-01-3100:02
null
2 March 2025
null
null
null
null
null
null
✓ 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
SELECTTRY_TO_TIMESTAMP(Local, 'DD/MM/YYYY') AS result
FROM input
ORDERBY id
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.