[英]String to DateTime BigQuery
I have a column with strings as datetimes.我有一列字符串作为日期时间。 I want to convert the whole column to datetime format.
我想将整列转换为日期时间格式。
Example
"19.03.2020 08:14:13"
"30.04.2020 08:57:45"
I tried this:我试过这个:
select *,
PARSE_DATETIME("%d%m%y %H:%M:%S", Example) as Date_example
from xx.yy.zz
but i got an error Failed to parse input string "19.03.2020 08:14:13"但我收到一个错误Failed to parse input string "19.03.2020 08:14:13"
Can anyone help me and tell me why this is not working?任何人都可以帮助我并告诉我为什么这不起作用吗? Is it because day,month and year are separated by the dot instead of slash?
是因为日、月、年是用点而不是斜线分隔的吗?
Consider:考虑:
PARSE_DATETIME('%d.%m.%Y %H:%M:%S', example) as Date_example
Rationale:理由:
your original format specifier is missing the dot separator between the date components您的原始格式说明符缺少日期组件之间的点分隔符
you want %Y
rather than %y
for the year component (the former is a 4 digits year, while the later is 2 digits)你想要
%Y
而不是%y
作为年份部分(前者是 4 位数年份,而后者是 2 位数)
We can shorten the query a little with %T
:我们可以使用
%T
稍微缩短查询:
PARSE_DATETIME('%d.%m.%Y %T', example) as Date_example
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.