简体   繁体   中英

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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