Home > Mobile >  Convert TIME to INT in BigQuery
Convert TIME to INT in BigQuery

Time:12-11

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.

CodePudding user response:

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: enter image description here

  • Related