Problems / Mixed Date Formats / Editorial
strptime
try_strptime
coalesce(try_strptime(s, '%Y-%m-%d'), try_strptime(s, '%m/%d/%Y'), try_strptime(s, '%Y/%m/%d'))
date_trunc('month', parsed)
COUNT(*)
ORDER BY month
In the PySpark variant, SQLFrame translates F.to_date(col, fmt) into a strict parse that errors on non-matching rows, so the reliable route is F.expr with the same DuckDB try_strptime + coalesce expression.
F.to_date(col, fmt)
F.expr
coalesce
The try-parse + coalesce chain is the standard idiom for *heterogeneous* string data: convert each candidate interpretation into a nullable value, then let precedence pick the winner. The subtle danger in mixed date columns is silent misparsing, not failed parsing — '05/03/2024' parses happily as both US (May 3) and day-first (March 5) conventions. Here the answer is unambiguous only because the three formats are structurally distinct; the data even includes US strings with day > 12 (like '03/25/2024') that would break a day-first assumption loudly rather than silently.
'05/03/2024'
Solve Mixed Date Formats yourself →