Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How I can write the sql query to find the time difference between 2 dates

495750Mar 5 2006 — edited Mar 6 2006
Hi

I am developing a report to find the time difference between each approval heirarchy to approve the purchase orders. I want display the exact day hour minute and second between one person to another person. In this I need to exclude the weekend days which is thursday and friday. Plus I have to calculate only the working hours. I mean our working hours are from 8.00 A.M to 4.00 P.M. I should not consider the hours after or before these hours.
Please anyone can help me how I can write function or sql calculate the time difference. I created one function to exclude thursday and friday which is my weekend I am posting it
CREATE OR REPLACE FUNCTION xxdcciweek_end(date1 IN DATE DEFAULT SYSDATE,date2 IN DATE DEFAULT SYSDATE+7) RETURN number AS

max_date date := GREATEST(date1,date2);
min_date date := LEAST(date1,date2);
no_of_weekend number := 0;
count_date date := min_date;

BEGIN
WHILE count_date <= max_date LOOP
IF TO_CHAR(count_date,'DY') IN ('THU','FRI') THEN
no_of_weekend := no_of_weekend+1;
END IF;
count_date := count_date+1;
END LOOP;
return (max_date-min_date) - no_of_weekend;
END;
/
and sql command to calculate the hour minute and second is

to_char(to_date('00:00:00','HH24:MI:SS') +
(Max(PA.ACTION_DATE) - Max(PB.ACTION_DATE)), 'HH24:MI:SS')

I appreciate the answer

Many Thanks

Asif
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 3 2006
Added on Mar 5 2006
2 comments
583 views