I want to subtract 2 dates and represent the result in hour and minute in one decimal figure.
I have the following table and I am doing it in this way but the result is not as desired.
There is some slight variation, I'm sure this is simple arithmetic but I'm not getting it right.
select start_time, end_time, (end_time-start_time)*24 from
come_leav;
START_TIME END_TIME (END_TIME-START_TIME)*24 ------------------- ------------------- ------------------------ 21-06-2011 14:00:00 21-06-2011 16:55:00 2.9166667 21-06-2011 07:00:00 21-06-2011 16:50:00 9.8333333 21-06-2011 07:20:00 21-06-2011 16:30:00 9.1666667
I want the result (end_time-start_time) as below.
16:55- 14:00 = 2.55 16:50-07:00 = 9.5 16:30-7:20 = 9.1 and so on.
How can I do that?
This is a very ugly way to do it, and this first part doesn't exactly question by the OP, but it gives a way to get results by subtracting 2 date fields -- in my case, the
CREATED_DATE
and today represented bySYSDATE
:It delivers the output as x years, x months, x days, x hours, x minutes. It could be reformatted however you like by changing the concatenated strings.
To more directly answer the question, I've gone ahead and written out how to get the total hours with minutes as
hours.minutes
:Oracle represents dates as a number of days, so
(end_time-start_time)*24
gives you hours. Let's assume you have this number (eg.2.9166667
) inh
column. Then you can easily convert it to the format you want with:FLOOR(h) + (h-FLOOR(h))/100*60
.Example:
In your case: