How to count days between two dates excluding saterady and sunday
Hi all
iam working on oracle sql/plsql.
In my application , i need to caliculate leave days between two dates excluding saterady and sunday
Please tell me the solution if any one knows
thanks in advance ,
balu
More modern version:
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');Thank you,
Tony Miller
Webster, TX
Never Surrender Dreams!
JMS
If this question is answered, please mark the thread as closed and assign points where earned..
Similar Messages
-
Day between two dates excluding Saturday and Sunday
Hi,
I have the Requirement like : there are two inputs in query 1)startdate and 2)end date when end user enter the start date and end date the sql query has to retrive the number of days between given start and end dates, and it should be retrivied with two condition 1)all sundays between the above dates excluded 2)second and fourth Saturday of the month in between the start and end dates has to be excluded .
example start date:01-may-09
end date: 16-may-09
expected output:13Balaji.M wrote:
Hope this will be helpful for you.
SELECT dates,
TO_CHAR(dates, 'D'),
TO_CHAR(dates, 'DAY'),
TO_CHAR(inner.dates, 'W')
FROM (SELECT TO_DATE('01-may-09') + LEVEL - 1 dates
FROM DUAL
CONNECT BY LEVEL <= (TO_DATE('16-may-09') - TO_DATE('01-may-09')) + 1) inner
WHERE ( ( TO_CHAR(inner.dates, 'D') = 7
AND TO_CHAR(inner.dates, 'W') NOT IN(2, 4)
OR TO_CHAR(inner.dates, 'D') not in (1,7)
You can replace the start date (two place) and end date (one place) by variables and check.Of course we have to be aware of local NLS settings:
SQL> SELECT dates,
2 TO_CHAR(dates, 'D'),
3 TO_CHAR(dates, 'DAY'),
4 TO_CHAR(inner.dates, 'W')
5 FROM (SELECT TO_DATE('01-may-09') + LEVEL - 1 dates
6 FROM DUAL
7 CONNECT BY LEVEL <= (TO_DATE('16-may-09') - TO_DATE('01-may-09')) + 1) inner
8 WHERE ( ( TO_CHAR(inner.dates, 'D') = 7
9 AND TO_CHAR(inner.dates, 'W') NOT IN(2, 4)
10 )
11 OR TO_CHAR(inner.dates, 'D') not in (1,7)
12 );
DATES T TO_CHAR(D T
01-MAY-09 5 FRIDAY 1
02-MAY-09 6 SATURDAY 1
03-MAY-09 7 SUNDAY 1
05-MAY-09 2 TUESDAY 1
06-MAY-09 3 WEDNESDAY 1
07-MAY-09 4 THURSDAY 1
08-MAY-09 5 FRIDAY 2
09-MAY-09 6 SATURDAY 2
12-MAY-09 2 TUESDAY 2
13-MAY-09 3 WEDNESDAY 2
14-MAY-09 4 THURSDAY 2
15-MAY-09 5 FRIDAY 3
16-MAY-09 6 SATURDAY 3
13 rows selected.
SQL>Day 1 on my local database is Monday, not Sunday. -
How to get the dates between Two dates excluding Saturaday and Sunday
Dear All,
select to_date('25-04-2012', 'DD-MM-YYYY') + rownum -1 dt
from dual
connect by level <= to_date('05-05-2012', 'DD-MM-YYYY') - to_date('25-04-2012', 'DD-MM-YYYY') + 1;The above query returning the following output,
DT
DT
04/25/2012
04/26/2012
04/27/2012
04/28/2012
04/29/2012
04/30/2012
05/01/2012
05/02/2012
05/03/2012
05/04/2012
05/05/2012here I need to exclude the Dates which comes on 'saturday' and 'sunday' and also the common holiday
Here it is '01-May-2012' and I need the output like the following,
04/25/2012
04/26/2012
04/27/2012
04/30/2012
05/02/2012
05/03/2012
05/04/2012I need the common query to calculate between any two dates.
Can anyone suggest me?
Thank you,
Regsrds,
gurujothiHi Frank,
Sorry for my fault,
The following is my table description,
CREATE TABLE "DATES"
( "FROMDATE" DATE,
"TODATE" DATE,
"LEAVE_ID" Number(5)
Insert into dates values('05-02-2012','05-05-2012',1);
Create table holiday_dates(holidays date);
insert into holiday_dates values('01-05-2012');Now when I used this query,
select count(*) from (select dt
from(
select to_date(fromdate, 'DD-MM-YYYY') + rownum -1 dt
from dates
connect by level <= to_date(todate, 'DD-MM-YYYY') - to_date(fromdate, 'DD-MM-YYYY') + 1
where to_char(dt,'fmday') not in ('sunday','saturday') minus (select holidays from holiday_dates)) dual;
Count(*)
64
Insert into dates values('01/05/2012','05/05/2012',2);
/Now my table has 2 rows,
select * from dates;
FROMDATE TODATE LEAVE_ID
01/05/2012 05/05/2012 1
05/02/2012 05/05/2012 2Now when I used this query,
select count(*) from (select dt
from(
select to_date(fromdate, 'DD-MM-YYYY') + rownum -1 dt
from dates
connect by level <= to_date(todate, 'DD-MM-YYYY') - to_date(fromdate, 'DD-MM-YYYY') + 1
where to_char(dt,'fmday') not in ('sunday','saturday') minus (select holidays from holiday_dates)) dual;The output is ,
COUNT(*)
1987How to get the output using the max(leave_id) like the following,
select..........from... where leave_id=(select max(leave_id) from dates);where to add "WHERE" clause in the above query?
Thank you,
Regards,
Gurujothi.
Edited by: Gurujothi on May 3, 2012 8:43 PM
Edited by: Gurujothi on May 3, 2012 8:44 PM -
How to get days between two dates
Hi ,
How to get days between two dates.
Regards,
Ramesh.Hi Ramesh,
REPORT ZDATEDIFF.
DATA: EDAYS LIKE VTBBEWE-ATAGE,
EMONTHS LIKE VTBBEWE-ATAGE,
EYEARS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
exporting
i_date_from = FROMDATE
i_date_to = TODATE
I_FLG_SEPARATE = ' '
IMPORTING
E_DAYS = EDAYS
E_MONTHS = EMONTHS
E_YEARS = EYEARS.
WRITE:/ 'Difference in Days ', EDAYS.
WRITE:/ 'Difference in Months ', EMONTHS.
WRITE:/ 'Difference in Years ', EYEARS.
INITIALIZATION.
FROMDATE = SY-DATUM - 60. -
How to calculate days between two DATES
How to calculate days between two DATES ?
which is the functional module for that ?
help meHi,
use function module : it works,
HR_HK_DIFF_BT_2_DATES
give output format = 03 and get the value in days.
code is as below :
data : DATE1 type P0001-BEGDA,
DATE2 type P0001-BEGDA,
YEARS type P0347-SCRYY,
MONTHS type P0347-SCRMM,
DAYS type P0347-SCRDD.
date1 = '20070331'.
date2 = '20070101'.
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
DATE1 = date1
DATE2 = date2
OUTPUT_FORMAT = '03'
IMPORTING
YEARS = years
MONTHS = months
DAYS = days
EXCEPTIONS
INVALID_DATES_SPECIFIED = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write : days.
Reward points, if helpful,
Regards,
Sandeep Kaushik -
Count days between two dates without weekend
Hi,
I need a solution in query or another thread, that returns the count of days between two dates without consider weekend (saturday and sunday) , I have the columns of type Date, and the return need in format of hours in one column hh:mm:ss and days in another column.
Regards
JonasHi and welcome to the forum.
Keep in mind that you can do a search on this forum.
Your question has been asked before.
Some other pointers:
http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551242712657900129
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:185012348071 -
How to retrieve day between two dates?
Hi all,
Hope doing well,
sir i am retrieving day between two dates in sql server like this.
select datediff(day,'2012-10-03 00:00:00.000','2012-10-05 00:00:00.000')
and getting result that is: 2
but how this type of query i'll use in oracle?
thanks,Just do minus
diff := date_variable2-date_variable1;The difference sill be in days.
If you want just the differences in days (Neglecting time part)
diff := trunc(date2)-trunc(date1); -
How to calculate days between 2 dates excluding public holidays over SAP ?
Hi
Have a universe over SAP data. Trying to calculate days between 2 dates. SAP holds Public Holiday data in various tables e.g Thol and data is updated via scal. Using my univeres as a source I want to run reports for different countries so need to have various bank holidays not just UK. In SAP function modules handle this. Has anyone designed a solution to cater for this situation in a universe ?
Thanks in advance
MHi,
I assume you mean SAP R/3 (ECC) when you write SAP and SAP BW.
Are you using BW? If so, I would load the data into SAP BW, create a query using customer exit variables and build your universe on top of that...
-J -
Calculate the Difference Between two dates excluding weekends and Holidays
Hi,
We need to calculate the difference between the two dates by excluding the Local public holidays (It is global and varies across countries) and weekends should not be included in calculation for a business day in OBIEE.
We have two dates: Open date and close date when ever close date is null we are calculating age based on taking the current timestamp and need to exclude the weekends and Holidays when ever the close date is null.
Ex:
Col1 col2 Total
11/9/2010 2:46:38 PM Null 13
11/2/2010 8:06:26 PM 11/3/2010 5:37:03 PM 1
(In the Total we shouldn't include the weekends,holidays)
Please let me know how to calculate the difference between two dates by excluding the weekends and holidays.
Thanks
Edited by: user10441472 on Nov 22, 2010 3:14 PMYou already asked this question and I answered it...
Re: calculation of Business day in OBIEE -
How to caluclate tat between two dates of one timestamp field
Hi,
could some one help how to caluclate days between two dates of single timestamp filed and with this
query
Select * from m_activity_transaction where actn_opp_id in (
Select actn_opp_id from m_activity_transaction where ACTN_ACTV_ID = 218
Group by actn_opp_id
having count(*) > 1 ) and ACTN_ACTV_ID = 218
order by actn_performed_on
iam getting output is
ACTN_ID ACTN_OPP_ID ACTN_PERFORMED_ON
319415 95831 27-JAN-12 11.06.20.000000 AM
315249 95831 08-FEB-12 05.32.54.000000 PM
301927 103509 20-DEC-11 04.01.43.000000 PM
301458 103509 19-DEC-11 04.51.03.000000 PM
294841 115840 10-JAN-12 03.20.12.000000 PM
312062 115840 11-JAN-12 05.17.06.000000 PM
and i nedd to caluclate no.of days between two dates like 27-JAN-12 11.06.20.000000 AM and 08-FEB-12 05.32.54.000000 PM where actn_id is unique AND ACTN_OPP_ID IS NOT UNIQUE.
Thanks in Advance,
vvr.This way?
with data as
select 315249 a, 95831 b, to_timestamp('27-JAN-12 11.06.20.000000 AM', 'DD-MON-RR HH.MI.SS.FF6 AM') dt from dual union all
select 319415, 95831, to_timestamp('08-FEB-12 05.32.54.000000 PM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual union all
select 301927, 103509 , to_timestamp('20-DEC-11 04.51.03.000000 PM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual union all
select 301458 , 103509 , to_timestamp('19-DEC-11 04.01.43.000000 PM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual union all
select 363810 , 144656 , to_timestamp('27-JUN-12 12.43.28.000000 PM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual union all
select 363500 , 144656 , to_timestamp('26-JUN-12 11.41.50.000000 AM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual union all
select 363354 , 144656 , to_timestamp('25-JUN-12 12.41.13.000000 PM', 'DD-MON-RR HH.MI.SS.FF6 AM') from dual
select a, b, diff
from (
select a, b, extract( day from (dt - lag(dt) over (partition by b order by dt, a)) ) diff
from data
) tab
where tab.diff is not null;
A B DIFF
319415 95831 12
301927 103509 1
363500 144656 0
363810 144656 1 -
How to query the number of working days between two dates
I'm looking for a solution to calculate the number of <i>working</i> days between two dates that I can use in a formated search.
Calculating the total number of days is pretty straight forward but does anyone know how to take into account the settings in the HLD1 (Holiday Dates) table?Hi Eric,
If you are purely looking to exclude holidays defined in the HLD1 table, then you should be able to do it with the following query
NOTE: The following query is an example using OINV table and the fields DOCDATE and DOCDUEDATE for a Particular DOCNUM 'xxx'
If you planning to use within the SAP module then replace DOCDATE and DOCDUEDATE with dynamic field references $[$x.x.x]
SELECT DATEDIFF(DAY,T0.DOCDATE,T0.DOCDUEDATE)-
(SELECT COUNT(STRDATE) FROM HLD1 WHERE STRDATE >= T0.DOCDATE AND STRDATE <= T0.DOCDUEDATE)
FROM OINV T0
WHERE T0.DOCNUM = xxx
Best Wishes
Suda -
I wanted to know how do you calculate the number of days between two dates
i wanted to know how do you calculate the number of days between two dates in java ? i get both the dates from the database. i guess there are many issues like leap year and Febuary having diff no of months ..etc.
thanks..
I solve my problem as
public class MyExample {
public static void main(String a[]) {
String stdate = "2009-03-01";
java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
java.sql.Date preDate = java.sql.Date.valueOf(stdate);
System.out.println(currentDate);
System.out.println(preDate);
// int dateCom = preDate.compareTo(currentDate);
// System.out.println(dateCom);
long diff = currentDate.getTime() - preDate.getTime();
int days = (int) Math.floor(diff / (24 * 60 * 60 * 1000));
System.out.println(days);
} -
How can i get number of days between two dates represented by two dates?
how can i get number of days between two dates represented by two date objects. One is java.sql.Date, the other is java.util.Date?
tej_222 wrote:
But how do I do that conversion. from java.sql.date and java.util.date to calender?
-thanks for the quick response.You may find the following utility code samples useful:
[http://balusc.blogspot.com/2007/09/calendarutil.html]
[http://balusc.blogspot.com/2007/09/dateutil.html]
ganeshmb wrote:
(date1.getTime() - date2.getTime())/(1000*60*60*24) should do.
getTime returns millsecond value of date object and the difference divided by no of milliseconds in a day should fetch you the difference in terms of days.This doesn't respect the DST. Use java.util.Calendar. -
How can I calculate the maximum number of days between two dates in a range of dates?
I have a column of dates spanning the couse of a few months. I would like to know if I can calculate the maximum number of days between each row and display the highest number. I currently have another column that calculates the days betwen the rows and I am currently just looking at the totals and highlighting the highest period.
Is this possible? Any help or suggestions are appreciated.
Thank you,
TrevorThis sounds totally possible, Can you post a screen shot of your table to make responding more focused? If you mean you want to:
A) compute the difference (in days) between two date in the same row, then
B) find the max duration (in days)
Here is my take on this problem:
D2 = C2-B2
select D2 and fill down
F1=MAX(D)
to perform the conditional formatting (to highlight the max duration) select column D, then set up conditional formatting as shown in the 1st image -
Working days between two date fields and Changing Factory Calendar
Hi,
I have to calculate working days between two date fields excluding the weekends and public holidays for Switzerland.
I have written the routine using factory calender and its working fine except for two problems now:
1. If any one of the date field is empty then teh rsult should be zero.
2. And the below code is working from 1996 but my cleints wants it to work for years before 1996 as well.
I also tried to change the Start date in SCAL for factory calendar but it says enter values between 1995 to 2020.
I am new to ABAP. Please help me how i can achieve these for below code.
DATA: IT_HOLIDAYS type TABLE OF ISCAL_DAY,
IS_HOLIDAYS TYPE ISCAL_DAY.
DATA: T_DATE TYPE SY-DATUM,
P_DATE TYPE SY-DATUM.
DATA : X_DATE(4) TYPE C.
DATA: CNT TYPE I.
REFRESH : IT_HOLIDAYS.
CLEAR : IT_HOLIDAYS.
T_DATE = SOURCE_FIELDS-/BIC/ZCCCHP812.
P_DATE = SOURCE_FIELDS-/BIC/ZCCCHP810.
CALL FUNCTION 'HOLIDAY_GET'
EXPORTING
HOLIDAY_CALENDAR = 'CH'
FACTORY_CALENDAR = 'CH'
DATE_FROM = P_DATE
DATE_TO = T_DATE
TABLES
HOLIDAYS = IT_HOLIDAYS
EXCEPTIONS
FACTORY_CALENDAR_NOT_FOUND = 1
HOLIDAY_CALENDAR_NOT_FOUND = 2
DATE_HAS_INVALID_FORMAT = 3
DATE_INCONSISTENCY = 4
OTHERS = 5.
DESCRIBE TABLE IT_HOLIDAYS LINES CNT.
X_DATE = T_DATE - P_DATE - CNT.
RESULT = X_DATE.
Please help
Regards
Zabina
Edited by: Syed786 on Nov 2, 2011 9:15 AMHi Zabina,
Try this function module 'DURATION_DETERMINE'.
Give the factory calendar and unit as DAY
With regards,
Rajesh
Maybe you are looking for
-
Error during creation of entry sheet via BAPI
Hi all, I have a problem with that bapi and that user exit. I can create a entry sheet with the bapi BAPI_ENTRYSHEET_CREATE and get it accepted using the flag BAPIESSRC-ACCEPTANCE of the header. But if i use the enhancement SRVEDIT in order to do a c
-
I have just migrated from Final Cut Studio to Final Cut Pro X. I am trying to get my head around the workflow of managing clips and sub-clips. I am working on an interview, so I have a master shot which was recorded to tape and lasts an hour or so
-
Moved location of Pages in "Applications", now can't save "Permission Denied"
To make things easier to me I moved my iWork applications out of the iWork '09 folder and into just applications. That way I didn't have to click on applications, then the iwork folder, then the program I wanted, they are now in order with my other
-
I need to talk to someone on AIM or MSN, because...
...the board will take to long for what I need to ask. I have questions about making a chat server, that I need a constant conversation going. So could someone give me their S/N and I'll message you? Thanks
-
Hi, I have just uploaded an excel spreadsheet to iCloud and then downloaded to my iPad. When I attempt to open on iPad I get an error message that says "Spreadsheet cannot be imported....to many formula in spreadsheet to be imported..." What are the