Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

snowflake convert string to timestamp

I have a timestamp string value from source data which I wanted to convert into required format. Any idea on converting the string into timestamp is much appreciated.

String value of source data
'Fri Oct 16 03:27:06 PDT 2020'

I want above string to be converted into 
YYYY-MM-DD HH24:MI:SS

which should be like from the sample string shared
2020-10-16 03:27:06

As of now trying with below, but this sounds like not a good practice to have.

select to_timestamp(substr('Fri Oct 16 03:27:06 PDT 2020',5,15)||' '||substr('Fri Oct 16 03:27:06 PDT 2020',25),'MON DD HH24:MI:SS YYYY');

Any help to achieve the desired output would be great. Thanks!

like image 403
Maran Avatar asked May 01 '26 11:05

Maran


1 Answers

After converting it to timezone, you can show it in any format:

select to_varchar(  to_timestamp( 'Fri Oct 16 03:27:06 PDT 2020', 'DY MON DD HH24:MI:SS TZD YYYY') , 'YYYY-MM-DD HH24:MI:SS') ;

Clean version:

SELECT to_varchar( column1, 'YYYY-MM-DD HH24:MI:SS') 
FROM VALUES (to_timestamp( 'Fri Oct 16 03:27:06 PDT 2020', 'DY MON DD HH24:MI:SS TZD YYYY'));
like image 162
Gokhan Atil Avatar answered May 03 '26 17:05

Gokhan Atil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!