I have a string column with date-time values that I need to convert into dates in order to calculate a dense rank.
This column can have any of the below 3 formats:
MM-DD-YYYY H:MM:SS PM
M-DD-YYYY H:MM:SS PM
MM-D-YYYY H:MM:SS PM
My SQL Statement to calculate the dense rank is based on this date-time column that I need to convert to date in order to rank descending:
DENSE_RANK()
OVER (PARTITION by [columnA] ORDER BY
TO_DATE(SUBSTRING([dateColumn],0,8), 'MM-DD-YYYY') DESC)
However, I'm stuck with the TO_DATE function since I have three different formats in the same column.
How can I make TO_DATE in Amazon Redshift work with multiple date formats in the same column?