问题
Convert DB2 SQL Decimal to time I need to convert Decimal to time. I have a decimal time field that contains data like this :
123490 --12:34:90
4506 --00:45:06
171205 --17:12:05
etc
I would like to convert into time format then i calculate min between two times columns
Is there anyway to do this with SQL commands or DB2 logic in a select statement?
回答1:
To convert it to a valid time format you have to do some string manipulations like
cast( substr( right( '00' || '123456', 6) ,1,2) || ':' || substr( right( '00' || '123456', 6) ,3,2) || ':' || substr( right( '00' || '123456', 6) ,5,2) as time)
where 123456 is your decimal. This would work for your 4506 example as well. You could of cause also use a case statement if you want to avaoid adding the "00" each time.
For calculating the difference in minues there might be other calc options. You can check out the minutes_between function provided by Db2 11.1
来源:https://stackoverflow.com/questions/51080212/convert-db2-sql-decimal-to-time