[英]How to Convert STRING to DATETIME in BIG QUERY
I Have TS
column in data.table
which contains String Like this '20220205183013', I want to convert it to datetime format like this 2022-02-05 18:20:18 UTC.我在data.table
中有TS
列,其中包含这样的字符串 '20220205183013',我想将其转换为这样的日期时间格式 2022-02-05 18:20:18 UTC。
I have tried this query but failed.我试过这个查询但失败了。
select CAST(ts AS TIMESTAMP 'YYYY-MM-DD HH24:MI:SS') as data_k from data_
and和
select PARSE_DATETIME("%a %b %e %Y %I:%M:%S",ts) from data_
but it still failed.但它仍然失败了。
You could use PARSE_TIMESTAMP
here with the correct format mask:您可以在此处使用带有正确格式掩码的PARSE_TIMESTAMP
:
SELECT PARSE_TIMESTAMP('%Y%m%d%H%M%S', '20220205183013');
The mask you were using with PARSE_DATETIME
does not match the input timestamp, which is in the format %Y%m%d%H%M%S
.您在PARSE_DATETIME
中使用的掩码与格式%Y%m%d%H%M%S
的输入时间戳不匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.