Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Working Days in SQL

Status
Not open for further replies.

TimboA

MIS
Jul 12, 2001
38
GB
I need to calculate the number of working days between two dates using pure SQL (ie can't use WORK_DAYS). Anyone know how this can be achieved??

many thanks in advance.

timboa
 

Try this:

-- --------------------- Begin ----------------------------

Set feedback off echo off autop off ver off

ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY';

accept MONTH char format 'A3'-
prompt'Enter MONTH for which U want the number of working days (like JAN..):'

accept YEAR char format 'A4'-
prompt'Enter the 4 digit Year (like 1999...):'

select count(*) NUM_WORK_DAYS
from (select to_date( '01-&MONTH-&YEAR', 'dd-mon-yyyy' )+rownum-1 day
from all_objects
where rownum < to_number( to_char( last_day( '01-&MONTH-&YEAR' ),'DD' ) )+1)
where to_number(to_char(day,'d')) between 2 and 6
/

-- ------------------------ End ---------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top