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?
Try this
This query is very usefull for me and if any body want diffrence between start_date and end_date with time like HH:MI:SS please use this query.
Edit: if you need a number, then
For string result, if delta is LESS THAN 24H: I would go with
or
...'HH24:MI:SS'
, but thats my personal preference.for longer than 24H terms, I would prefix with
Yes, as oracle counts in days, with seconds precision, you are dealing with arithmetical problems. Once because you are only handling minutes (so you might round your number to
trunc(days*24*60+0.5)/24/60
), but the binary arithmetic imprecision on the number 1/24/60 might still cause you troubles.Edit2.1:
But The result could be quite confusing for the average, as the decimal 7.50 would suggest seven and a half hour, or at least 7 hour 50 minutes, opposed to the elapsed time of 7 hours 10 minutes.
It should be noted for those coming across this code that the decimal portions are ACTUAL minute differences, and not part of an hour.
.5
, therefore, represents50 minutes
, not30 minutes
.try this:
you can work with the extract: