Monday, August 6, 2018
Oracle Function PLSQL Conversion date to number hour min
Oracle Function PLSQL Conversion date to number hour min
Oracle Function : Conversion date to number (hour,min) |
Use this function to get conversion date variable to number(hour,min) :
The function would generate date variable, ( date1-date2) becomes number (hour,min)
FUNCTION GET_DURATION(d1 number) RETURN VARCHAR2 IS
--# d1 = tanggal awal
--# d2 = tanggal akhir
tmpvar VARCHAR2(100);
durdays NUMBER(20, 10); -- days between two dates
durhrs BINARY_INTEGER; -- completed hours
durmin BINARY_INTEGER; -- completed minutes
dursec BINARY_INTEGER; -- completed second
durhari PLS_INTEGER;
jhrs number;
jmin number;
thrs number;
BEGIN
durdays := d1;
durhari := TRUNC(d1);
durhrs := MOD(TRUNC(24 * durdays), 24);
durmin := MOD(TRUNC(durdays * 1440), 60);
dursec := MOD(TRUNC(durdays * 86400), 60);
jhrs :=(to_number(durhari)*24)+to_number(durhrs||.||lpad(durmin,2,0));
thrs :=jhrs;
RETURN(thrs);
END get_duration;
How to use :
select GET_DURATION(date_variable) from dual;
example :
example :
select GET_DURATION(date1-date2) from dual;or
select GET_DURATION((date1-date2)-(date3-date4)) from dual;