简体   繁体   中英

Convert TIME to INT in BigQuery

One of my columns is coming up as a TIME type but I would like it to come up as an INT type because the values aren't translating well in Tableau.

I tried running the CAST function like so:

CAST(ride_length AS INT) AS ride_length,

Someone in a previous question suggested the following:

SELECT (DATEPART(hour, Col1) * 3600) + (DATEPART(minute, Col1) * 60) + DATEPART(second, Col1) as SecondsFromMidnight FROM T1;

DATEPART does not work in BigQuery and I don't see a DATE function that would work on the documentation.

Converting a TIME to seconds:

SELECT (EXTRACT(HOUR FROM TIME(ride_length)) * 3600) + (EXTRACT(MINUTE FROM TIME(ride_length))  * 60) + EXTRACT(SECOND FROM TIME(ride_length)) as SecondsFromMidnight FROM T1;

More info: https://cloud.google.com/bigquery/docs/reference/standard-sql/time_functions#extract

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