How would you calculate the difference between two dates?
Calculate Difference Between Dates in SQL*Plus or PL/SQL
Collapse
X
-
Procedure to find difference between dates !
Use following procedure... which i got from one site ....Originally posted by bradleycHow would you calculate the difference between two dates?
it will help u....
Code:CREATE OR REPLACE PROCEDURE PRINT_DATE_DIFF(p_dte1 IN DATE, p_dte2 IN DATE) IS v_diff NUMBER := 0; v_hrs NUMBER := 0; v_min NUMBER := 0; v_sec NUMBER := 0; BEGIN v_diff := ABS(p_dte2 - p_dte1); v_hrs := TRUNC(v_diff, 0)*24; -- start with days portion if any v_diff := (v_diff - TRUNC(v_diff, 0))*24; -- lop off whole days, convert --to hrs v_hrs := v_hrs + TRUNC(v_diff, 0); -- add in leftover hrs if any v_diff := (v_diff - TRUNC(v_diff, 0))*60; -- lop off hrs, convert to mins v_min := TRUNC(v_diff, 0); -- whole mins v_sec := TRUNC((v_diff - TRUNC(v_diff, 0))*60, 0); -- lop off mins, --convert to secs DBMS_OUTPUT.put_line( TO_CHAR(v_hrs) || ' HRS ' || TO_CHAR(v_min) || ' MIN ' || TO_CHAR(v_sec) || ' SEC'); END print_date_diff;
Last edited by Niheel; Dec 6 '05, 07:07 AM.
Comment