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
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
) in h
column. Then you can easily convert it to the format you want with: FLOOR(h) + (h-FLOOR(h))/100*60
.
Example:
WITH diff AS (
SELECT (TO_DATE('21-06-2011 16:55:00', 'DD-MM-YYYY HH24:MI:SS') - TO_DATE('21-06-2011 14:00:00', 'DD-MM-YYYY HH24:MI:SS'))*24 h
FROM dual
) SELECT FLOOR(h) + (h-FLOOR(h))/100*60
FROM diff
In your case:
SELECT start_time, end_time,
FLOOR((end_time-start_time)*24) + ((end_time-start_time)*24-FLOOR((end_time-start_time)*24))/100*60 AS hours_diff
FROM come_leav