差を数値として計算し、1 日の端数から計算できます。次のスクリプト例では、以下の出力が得られます
SET SERVEROUTPUT ON;
DECLARE
l_start_time date := sysdate;
l_end_time date := SYSDATE+1;
l_diff number;
BEGIN
dbms_output.put_line('start time='||l_start_time);
dbms_output.put_line('end time ='||l_end_time);
l_diff :=l_end_time-l_start_time;
dbms_output.put_line('a) difference days ='||to_char(l_diff));
dbms_output.put_line('a) difference hours ='||to_char(l_diff*24));
dbms_output.put_line('a) difference minutes='||to_char(l_diff*24*60));
dbms_output.put_line('a) difference seconds='||to_char(l_diff*24*60*60));
l_start_time := to_date('31/07/2012 20:00:00','DD/MM/YYYY HH24:MI:SS');
l_end_time := to_date('01/08/2012 04:15:44','DD/MM/YYYY HH24:MI:SS');
l_diff :=l_end_time-l_start_time;
dbms_output.put_line('b) difference days ='||to_char(l_diff));
dbms_output.put_line('b) difference hours ='||to_char(l_diff*24));
dbms_output.put_line('b) difference minutes='||to_char(l_diff*24*60));
dbms_output.put_line('b) difference seconds='||to_char(l_diff*24*60*60));
END ;
/
出力先:
start time=31-JUL-12
end time =01-AUG-12
a) difference days =1
a) difference hours =24
a) difference minutes=1440
a) difference seconds=86400
b) difference days =.3442592592592592592592592592592592592593
b) difference hours =8.26222222222222222222222222222222222222
b) difference minutes=495.733333333333333333333333333333333333
b) difference seconds=29744