简体   繁体   English

雪花将字符串转换为时间戳

[英]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!谢谢!

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'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM