Reputation: 85
How can I extract hour from timestamp/time column in BigQuery?
Timestamp Column sample value: 4/1/2020 12:57:55
Time Column sample value: 12:57:55
I have tried using
EXTRACT(minute from Timestamp)
split(Time,'')[ordinal(1)]
split
returns only one value and does not solve my concern.
Regular SQL extract does not work.
Upvotes: 0
Views: 5497
Reputation: 2365
As far as I could understand, your datetime column is formatted as string. So you need to parse it first to datetime.
SELECT EXTRACT(minute from PARSE_DATETIME('%e/%m/%Y %H:%M:%S', '4/1/2020 12:57:55'))
For time column, you can use this one:
SELECT EXTRACT(minute from CAST('12:57:55' AS time))
Upvotes: 1
Reputation: 1269563
To extract the hour from the scalar column, you can use:
EXTRACT(hour FROM Timestamp)
EXTRACT()
works for both TIMESTAMP
s and TIME
s.
Upvotes: 1