Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract TIME from DATETIME - informix

I have lost few hours looking for one row solution and didn't manage to find it. I have some value (2013/01/03 07:13:26.000) and I want to extract time part to get this: 07:13:26 so I can store it in another database as stage layer in ETL process.

When I try select my_datetime::datetime hour to second, I still get full timestamp.

Thanks.

EDIT: Sorry, source column is datetime, NOT timestamp.

like image 701
fenix Avatar asked Aug 01 '14 14:08

fenix


2 Answers

Ok, I managed to do this:

SELECT to_char(extend (my_datetime_column, hour to second),'%H:%M:%S') as my_time FROM my_table

Hope it will help someone!

like image 123
fenix Avatar answered Nov 15 '22 07:11

fenix


Try this:

SELECT CAST(datetime_field AS DATETIME HOUR TO SECOND) ...

Or

SELECT to_char(datetime_field, "%H:%M:%S") ...
like image 45
Ismael Avatar answered Nov 15 '22 08:11

Ismael