简体   繁体   English

在 Bigquery 中将字符串转换为日期(边缘情况)

[英]Convert string to date (edge case) in Bigquery

I have a column with a list of strings in a column that represent date and time, but the time is attached to the date with no space.我有一个列,列中有一个字符串列表,表示日期和时间,但时间附加到没有空格的日期。 I'm having trouble identifying the correct query to convert to datetime.我在确定要转换为日期时间的正确查询时遇到问题。

The original strings look like this:原始字符串如下所示:

April 22, 20229:00am 
 October 19, 202012:00pm 
 April 12, 20225:00pm 

I would like them to be in the date/time format:我希望它们采用日期/时间格式:

April 22, 2022 9:00am 
 October 19, 2020 12:00pm 
 April 12, 2022 5:00pm 



 

Consider below考虑以下

select original_col, 
  format_datetime('%B %d, %Y %R%p', parse_datetime('%B %d, %Y%R%p', original_col)) new_col
from your_table              

if applied to sample data in your question - output is如果应用于您问题中的样本数据 - output 是

在此处输入图像描述

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

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