By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 459,364 Members | 1,637 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,364 IT Pros & Developers. It's quick & easy.

# Calculate Difference Between Dates in SQL*Plus or PL/SQL

 P: 12 How would you calculate the difference between two dates? Oct 24 '05 #1
Share this Question
1 Reply

 P: 23 How would you calculate the difference between two dates? Use following procedure... which i got from one site .... it will help u.... Expand|Select|Wrap|Line Numbers  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;   Dec 6 '05 #2

### Post your reply

Sign in to post your reply or Sign up for a free account.