menachemgerst
menachemgerst

Reputation: 11

bigquery converting string to time mm:ss

how can I convert the string "average_time_per_KM" to time in the formt of mm:ss? I tryed using TIME and got an error 'Invalid time string "4:56"'Cast query to time format

is there a different function to cast in to mm:ss?

Upvotes: 1

Views: 925

Answers (2)

Cylldby
Cylldby

Reputation: 1978

You need to tell BQ what is the meaning of each digit in the string you give it. For that you need to use the PARSE_TIME function:

SELECT PARSE_TIME("%M:%S", average_time_per_KM)
FROM `your.table`

Upvotes: 0

Mikhail Berlyant
Mikhail Berlyant

Reputation: 173190

You can use any of below parse time that presented as string as minutes:seconds

PARSE_TIME("%M:%S", average_time_per_KM)

or

CAST(average_time_per_KM AS TIME FORMAT 'MI:SS')

Upvotes: 2

Related Questions