472,330 Members | 1,215 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 software developers and data experts.

How to get business days between two dates?

Hi!
There are two given dates and I have to find out the working days between two dates i.e. excluding Sundays. Please help. Thank you.
Feb 6 '08 #1
5 31365
amitpatel66
2,367 Expert 2GB
Hi!
There are two given dates and I have to find out the working days between two dates i.e. excluding Sundays. Please help. Thank you.
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT dt FROM
  3. (SELECT TO_DATE(:start_date,'DD-MON-YYYY') + level - 1 dt FROM table_name CONNECT BY level <= TO_DATE(:end_date,'DD-MON-YYYY') - TO_DATE(:start_date,'DD-MON-YYYY')) WHERE TO_DATE(dt,'Day') != 'Sunday';
  4.  
  5.  
PS: Not Tested!!
Feb 6 '08 #2
Hi!
There are two given dates and I have to find out the working days between two dates i.e. excluding Sundays. Please help. Thank you.

MODIFIED OF AMITH PETELS CODE
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT HIREDATE FROM 
  3. (SELECT TO_DATE(&start_date,'DD-MON-YYYY') + level - 1 HIREDATE FROM EMP
  4.  CONNECT BY level <= TO_DATE(&end_date,'DD-MON-YYYY') - TO_DATE(&start_date,'DD-MON-YYYY') ) 
  5. WHERE TO_DATE(HIREDATE,'Day') != 'Sunday'
  6. /
  7.  
Feb 7 '08 #3
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT dt FROM
  3. (SELECT TO_DATE(:start_date,'DD-MON-YYYY) + level - 1 dt FROM table_name CONNECT BY level <= TO_DATE(:end_date,'DD-MON-YYYY) - TO_DATE(:start_date,'DD-MON-YYYY')) WHERE TO_DATE(dt,'Day') != 'Sunday';
  4.  
  5.  
PS: Not Tested!!
Expand|Select|Wrap|Line Numbers
  1.  
  2. WITH date_tab AS
  3.          (SELECT       TO_DATE ('&from_date', 'dd-MON-yyyy')
  4.                      + LEVEL
  5.                      - 1 business_date
  6.                 FROM DUAL
  7.           CONNECT BY LEVEL <=
  8.                           TO_DATE ('&to_date', 'dd-MON-yyyy')
  9.                         - TO_DATE ('&from_date', 'dd-MON-yyyy')
  10.                         + 1)
  11.   SELECT business_date
  12.     FROM date_tab
  13.    WHERE TO_CHAR (business_date, 'DY') NOT IN ('SAT', 'SUN');
  14. //
  15.  

Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE OR REPLACE FUNCTION F_BUSINESS_DAYS
  3. (V_START_DATE IN DATE, V_END_DATE IN DATE)
  4. RETURN NUMBER IS DAY_COUNT NUMBER := 0;
  5. CURR_DATE DATE;
  6. BEGIN -- loop through and update
  7. CURR_DATE := V_START_DATE;
  8. WHILE CURR_DATE <= V_END_DATE
  9. LOOP
  10. IF TO_CHAR(CURR_DATE,'DY') NOT IN ('SAT','SUN')
  11. THEN DAY_COUNT := DAY_COUNT + 1;
  12. END IF;
  13. CURR_DATE := CURR_DATE + 1;
  14. END LOOP;
  15. RETURN DAY_COUNT;
  16. END F_BUSINESS_DAYS;
  17. //
  18.  
  19.  
Feb 7 '08 #4
Dear Subhashsavji,

The solution (WITH date_tab AS ) works fine...great query.

Many Thanks.
Oct 15 '10 #5
debasisdas
8,127 Expert 4TB
Also check this for more customized version.
Oct 18 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: David Stockwell | last post by:
I''m wondering if the Calendar object has an option to only do calculations based on business days (ie M-F). Additionally does it have a way to get...
12
by: Anthony Robinson | last post by:
Is anyone aware of a function (system or user defined) that will calculate business days? For instance: I have a column in as table called DATE. I...
1
by: igendreau | last post by:
I have users inputting a "Request Date". Upon entering a date, I need Access to populate a second field ("Due Date"). When they enter their...
4
by: CDMAPoster | last post by:
I'm starting to come up with a version of DateAdd that I call BusinessDateAdd that adds the selected number of business days. It's still in...
7
by: Sam | last post by:
Hi, I use C# in my ASP.NET projects. Here's what I need to do: I want to add x business days to a given date i.e. add 12 business days to today's...
2
by: brains4math | last post by:
Hi, is there a method in C# that calculates the number of business days between given dates, like networkdays in Excel? Thank you!
8
by: =?Utf-8?B?QWw=?= | last post by:
I am working in vb2005. how can I calculate business days (not including holidays and weekends) between 2 dates? thanks Al
1
by: santhoshrms | last post by:
I need to be able to determine the number of business days between two dates. Is there a function/Select Query in DB2 that can be used to do this? ...
5
FishVal
by: FishVal | last post by:
IMHO, the following is not a how-to-do instruction to solve a particular problem but more a concept-proof stuff demonstrating possibilities of SQL. ...
7
Jerry Maiapu
by: Jerry Maiapu | last post by:
Ok, I found a function that calculates/count business days excluding Weekends and holidays on the net. My country's Holiday dates are in a table...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.