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!

Calculate hours between two dates

EmaxGOct 24 2012 — edited May 21 2013
Hello,

I have a requirement to count hours with 2 given timestamps , something like :
SQL> select ((to_date('22-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss') - to_date('20-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss'))*24) B from dual ;

         B
----------
        48
However, I wish it would be as simple as this. I only need to count the hours between two timestamps during working hours e.g. 8 am - 5 pm and MON-FRI (exclude weekends).
So, lets say i have to count the hours between the two dates given above the result should be 18 hours, not 48 (4 hours on 20/oct, 9 hours on 21/oct and 5 hours on 22/oct).
How can I achieve this? Any insight will be helpful.

Thanks
This post has been answered by bencol on Oct 24 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 18 2013
Added on Oct 24 2012
7 comments
23,025 views