Edit: if you need a number, then
trunc(end_date-start_date)*24+ to_number(to_char(trunc(sysdate)+(end_date-start_date),'HH24.MI'))
For the result of the string, if delta is LESS THAN 24H: I would go with
to_char(trunc(sysdate)+(end_date-start_date),'HH24.MI')
or ...'HH24:MI:SS' , but this is my personal preference.
for more than 24 hours, I would prefix
trunc(end_date-start_date)||"days "|| to_char(trunc(sysdate)+(end_date-start_date),'HH24.MI')
Yes, since the oracle counts days, accurate to the second, you are dealing with arithmetic problems. Once, because you only process minutes (so you can round your number to trunc(days*24*60+0.5)/24/60 24/60), but the binary arithmetic inaccuracy on 1/24/60 can still cause problems .
Edit2.1:
to_char(24*(trunc(end_date)-trunc(start_date))+to_number(to_char(end_date,'HH24.MI'))-to_number(to_char(start_date,'HH24.MI')),'99999.99')
But the result can be quite confusing for the average value, since decimal 7.50 would suggest seven and a half hours or at least 7 hours 50 minutes, against a time equal to 7 hours 10 minutes.
vmatyi Sep 18 '11 at 19:14 2011-09-18 19:14
source share