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

时间:2020-10-16 11:16:43

标签: datetime timestamp snowflake-cloud-data-platform

我有一个源字符串中的时间戳字符串值,我想将其转换为所需的格式。将字符串转换为时间戳的任何想法都很受赞赏。

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

任何有助于获得所需输出的帮助都将非常有用。谢谢!

1 个答案:

答案 0 :(得分:2)

将其转换为时区后,可以以任何格式显示它:

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

干净版本:

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