Pages

Tuesday, March 19, 2013

Number of working days between any 2 given dates?


Write a query to calculate number of working days between any 2 given dates.
The working days here refer to the count of days excluding Saturdays and Sundays. Let us take the given 2 dates as ’26-Aug-2007′ and SYSDATE. (26th August is my Birthday).
The query looks like:
select count(val) Number_of_working_days from
(
select
to_number(to_char(to_date(’26-aug-07′)+rownum , ’D')) val,
to_char(to_date(’26-aug-07′)+ rownum) date1,
to_char(to_date(’26-aug-07′) + rownum, ‘Day’) day1
from
all_objects
where
to_date(’26-aug-07′)+rownum<= sysdate
)
where val not in (6,7)

1 comment: