How to convert String date dd-mmm-yyyy hh:mm specific format to Date format

Viewed 33

I'm currently working with CSV data and trying to import into data studio. The date variable is as string data type and format in CSV is "dd-mmmm-yyyy hh:mm" EXAMPLE: "6-Sept-2022 18:21:33".

How to convert string to date data type.

Please, I need help.

Regards

1 Answers

the month must be written like this 'Sep' or 'September' and then you can use

this for Sep:

select to_timestamp('6-Sep-2022 18:21:33','dd-Mon-yyyy HH24:MI:ss')::timestamp

this for September:

select to_timestamp('6-September-2022 18:21:33','dd-Month-yyyy HH24:MI:ss')::timestamp

documentation here

you can convert 'Sept' in 'Sep' with:

select to_timestamp( replace( '6-Sept-2022 18:21:33','Sept','September'),'dd-Month-yyyy HH24:MI:ss')
Related