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.
5 31953
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: -
-
SELECT dt FROM
-
(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';
-
-
PS: Not Tested!!
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 -
-
SELECT HIREDATE FROM
-
(SELECT TO_DATE(&start_date,'DD-MON-YYYY') + level - 1 HIREDATE FROM EMP
-
CONNECT BY level <= TO_DATE(&end_date,'DD-MON-YYYY') - TO_DATE(&start_date,'DD-MON-YYYY') )
-
WHERE TO_DATE(HIREDATE,'Day') != 'Sunday'
-
/
-
Try this: -
-
SELECT dt FROM
-
(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';
-
-
PS: Not Tested!!
-
-
WITH date_tab AS
-
(SELECT TO_DATE ('&from_date', 'dd-MON-yyyy')
-
+ LEVEL
-
- 1 business_date
-
FROM DUAL
-
CONNECT BY LEVEL <=
-
TO_DATE ('&to_date', 'dd-MON-yyyy')
-
- TO_DATE ('&from_date', 'dd-MON-yyyy')
-
+ 1)
-
SELECT business_date
-
FROM date_tab
-
WHERE TO_CHAR (business_date, 'DY') NOT IN ('SAT', 'SUN');
-
//
-
-
-
CREATE OR REPLACE FUNCTION F_BUSINESS_DAYS
-
(V_START_DATE IN DATE, V_END_DATE IN DATE)
-
RETURN NUMBER IS DAY_COUNT NUMBER := 0;
-
CURR_DATE DATE;
-
BEGIN -- loop through and update
-
CURR_DATE := V_START_DATE;
-
WHILE CURR_DATE <= V_END_DATE
-
LOOP
-
IF TO_CHAR(CURR_DATE,'DY') NOT IN ('SAT','SUN')
-
THEN DAY_COUNT := DAY_COUNT + 1;
-
END IF;
-
CURR_DATE := CURR_DATE + 1;
-
END LOOP;
-
RETURN DAY_COUNT;
-
END F_BUSINESS_DAYS;
-
//
-
-
Dear Subhashsavji,
The solution (WITH date_tab AS ) works fine...great query.
Many Thanks.
Also check this for more customized version.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
holidays into itself?
Currently I'm considering converting my calculations over to business days
and am wondering if there is anything built-in. I've tried searching but so
far haven't seen...
|
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 want to be able to add five business days to that date
and come up with a new date. Is that possible.
Also, is there anyway that DB2 can be aware of holidays? Maybe load
them onto the server in...
|
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
Request Date, I want Access to set the default value of Due Date =
Request Date + 9 Business Days (Holidays don't matter. Just want
Saturday and Sunday taken out). Any thoughts?
|
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 preliminary form (needs testing) and interacts with my direct
date functions (which have also changed slightly). There's no room to
put the code in the margins :-), but there's enough room to put up a...
|
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 date. What
is the best, fastest and most efficient way for me to do this?
--
Thanks,
Sam
| |
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!
|
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
|
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? ...
|
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.
So, let us say the problem is to calculate business days count which is defined as count of days (optionally inclusive in the current implementation) excluding weekend days and holidays.
Let us...
|
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 tblHolidays with fields. HolidayID,HolidayDate,HolidayName.
The Function:
Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
'-- Return the number of WorkingDays between...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |