Reputation: 37
When dealing with a Timestamp like '29-03-2021 15:30:02', I'm usually using operators like:
Year(Timestamp) AS Event_Year
Month(Timestamp) AS Event_Month
Week(Timestamp) AS Event_Week
Hour(Timestamp) AS Event_Hour
But this time I need to extract the time, having a column with '15:30:02'
.
I was thinking about something like Time(Timestamp) as Event_Time
but it doesn't seem like a command. Is there any smart solution to come across this?
Upvotes: 1
Views: 6112
Reputation: 2977
If it's already a Timestamp
data type, you can use cast
like this:
CAST(fieldname AS TIME)
Or if it's still a string, you would have to do this I think:
CAST(CAST(fieldname AS TIMESTAMP FORMAT 'dd-mm-yyyyBhh:mi:SS.s(1)') AS TIME)
(I forget the proper syntax for the timezone identifier)
Upvotes: 4