Solved

Date Count without Weekend

Posted on 2004-04-16
4
947 Views
Last Modified: 2008-03-17
Anyone has idea how to do this?
If I create a function to do this, will that affect the performance of the query a lot? Thank you
0
Comment
Question by:bob318
4 Comments
 
LVL 4

Expert Comment

by:BulZeyE
ID: 10845803
what do you want to count?? days possibly??  are you passing in the start and end???
0
 

Author Comment

by:bob318
ID: 10845846
I want to count the business date between 2 data parameter

0
 
LVL 3

Accepted Solution

by:
taisk earned 50 total points
ID: 10846600
If the database is Oracle,

CREATE OR REPLACE FUNCTION daysbetween
  (dateFrom in date, dateTo in date)
return number
IS
begin
declare
      days number;
begin
        days := dateTo-dateFrom+1;
        for i in 0 .. days-1 loop
              -- In my locale, the week starts Sun so Sun = 1, Sat = 7
              if to_char(dateFrom+i, 'd') in (1, 7) then
                      days := days - 1;
            end if;                      
        end loop;
        return days;
end;
end;

Obviously the function would not take public holidays into account.  You can easily modify it to look up a table that stores the dates for public holiday.

Similar logic may be used for SQL server and Access.
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 10848417
if you want to ount business days then you need a calendar table which tells you which days are valid
and then join that to your queries and count....

thats the only way your going to be able to account for public holidays or even half day openings ...

 
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Write Caching in the Cloud for VFP9 16 116
constraint check 2 40
Documenting Data flow 4 39
Server configuration for MS Access - SQL Server app 8 71
In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question