Changing time format and adding to date

General
Enthusiast

Changing time format and adding to date

Hello,

I have time in format HH:MM and date in format mm/dd/yyyy. I want COL1 with time formated as HH:MM:SS and COL2 a combination of COL1 and date in format MM/DD/YYYY HH:MM:SS.

Also, then I need to subtract COL3 (format mm/dd/yyy hh:mm:ss) from COL2.

How can I do this?

1 REPLY
Enthusiast

Re: Changing time format and adding to date

Something like will help you I think..

select
cast('09:26'||':00' as time) as col1,
CAST( current_date AS TIMESTAMP(0)) + (col1 - TIME '00:00:00' HOUR TO SECOND) as col2,
(current_timestamp - col2) DAY(4) TO SECOND as col3;

Thanks!

-Sakthi