Find time difference in 00:00:00(H24:MI:SS) between two dates
                                                 Last update (2008-02-20 12:35:25)
                                                                                                                   Date added (2008-02-20 12:24:45)

Summary
You can have the time difference in 00:00:00(Hours:Minutes:Seconds) between two dates(date1, date2) using this function
CREATE OR REPLACE FUNCTION Get_Time_Difference(v_Date1 IN DATE, V_date2 IN DATE) RETURN VARCHAR2
IS
  V_date_diff NUMBER;
  v_hours  VARCHAR2(10);
  v_min    VARCHAR2(5);
  v_sec    VARCHAR2(5);
  BEGIN
  v_date_diff:= ABS(v_Date1-v_Date2)*24*60*60;
  v_hours:=FLOOR(v_date_diff/3600);

   v_min:=FLOOR(((v_date_diff)-FLOOR((v_date_diff)/3600)*3600)/60);

   v_sec:=ROUND(((v_date_diff)-FLOOR((v_date_diff)/3600)*3600
      -(FLOOR(((v_date_diff)-FLOOR((v_date_diff)/3600)*3600)/60)*60)));
   RETURN v_hours||':'||v_min||':'||v_sec;
END Get_Time_Difference;
/
Example
sqlplus>select Get_time_Difference(:dat1, sysdate) from dual;
Reviews
Filters
Search