How can we convert numbers to 12 hour time format in Bigquery table

Viewed 327

My bigquery table has a column which is of below format

23:00 19:00 15:00

and I want to convert them to time format(AM/PM)

11:00 PM 07:00 PM 03:00 PM

Thanks in advance!!

1 Answers

Use parse_time and format_time:

select format_time('%I:%M %p', parse_time('%H:%M', '23:00'))

Try:

with mytable as (
  select '23:00' as column1 union all
  select '19:00' as column1 union all
  select '15:00' as column1
)
select format_time('%I:%M %p', parse_time('%H:%M', column1))
from mytable

enter image description here

Related