Reputation: 13
I have a column in the format YYYY-MM-DDBHH:MI:SS and I wish to extract just the hour and minutes from this into a column. Currently on the code they are using
Extract(HOUR From table) AS HR
, Extract(MINUTE From table) AS MN
but this outputs them into 2 columns. I'm new to SQL so is there an easier way to extract hour and minutes into one column in the format HH:MI.
Thanks
Upvotes: 1
Views: 2802
Reputation: 60472
If you got a Timestamp the easiest way to get a HH:MI
string is:
to_char(mycol, 'HH24:MI')
Upvotes: 0
Reputation: 16433
Using Teradata, simply concatenate the output from each of the functions to give the answer:
Extract(HOUR From table) || ':' || Extract(MINUTE From table) AS OUTPUT
Upvotes: 2
Reputation: 212
Don't know about teradata but something like this.
SELECT CONCAT(Extract(HOUR From table),Extract(MINUTE From table)) as HRandMI
Upvotes: 0