Each example runs on the same 9 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
What is the date of each order, without the time?
SQL (DuckDB)
SELECT CAST (Ordered AS DATE) AS result
FROM input
ORDER BY id
The time is dropped, not rounded: 23:59:59 stays on the same day.
| Ordered | Result |
|---|
| 2021-01-01 08:00 | 2021-01-01 |
| 2021-01-03 18:45 | 2021-01-03 |
| 2024-02-29 10:15 | 2024-02-29 |
| 2024-12-29 16:25:40 | 2024-12-29 |
| 2024-12-30 09:05 | 2024-12-30 |
| 2025-01-31 23:59:59 | 2025-01-31 |
| 2025-03-01 00:00 | 2025-03-01 |
| 2025-03-02 12:30:15 | 2025-03-02 |
| null |
✓ The Tableau formula and the SQL return the same 9 rows.
Which dates do the text values hold?
SQL (DuckDB)
SELECT
coalesce(try_cast(Text AS DATE), CAST (try_strptime(Text, '%B %d, %Y') AS DATE), CAST (try_strptime(Text, '%m/%d/%Y') AS DATE)) AS result
FROM input
ORDER BY id
Try ISO first, then "Month day, year", then US month/day/year. Row 3 has a time, which is dropped; rows 7 and 8 aren't dates and return null.
| Text | Result |
|---|
| 2021-01-01 | 2021-01-01 |
| January 3, 2021 | 2021-01-03 |
| 2024-02-29 10:15 | 2024-02-29 |
| 2024-12-29 | 2024-12-29 |
| 12/30/2024 | 2024-12-30 |
| 2025-01-31 | 2025-01-31 |
| 2025-02-29 | null |
| n/a | null |
| null |
✓ The Tableau formula and the SQL return the same 9 rows.