Can ClickHouse convert the string in format 'DD-MMM-YYYY' to Date?

Viewed 1829

Is there a function like that in clickhouse? Similar to mysql's STR_TO_DATE function.

I need to convert '04-Jun-2021' to '2021-06-04'

1 Answers

Consider using parseDateTime32BestEffort:

SELECT
    '04-Jun-2021' AS str,
    parseDateTime32BestEffort(str) AS dateTime,
    toDate(dateTime) AS date

┌─str─────────┬────────────dateTime─┬───────date─┐
│ 04-Jun-2021 │ 2021-06-04 00:00:00 │ 2021-06-04 │
└─────────────┴─────────────────────┴────────────┘
Related