How to exclude 'Saturday' and 'sunday' In APEX 4.1 count(*)
Hi everyone am using APEX 4.1,
The Leave_transaction Table has the following Fields,
1.Leave_id
2.Emp_name
3.From_date
4.To_date
5.Remaining_days
The Emp_Master Table has the following columns,
1.Emp_id
2.Emp_Name
3.Remaining_days
select count(*) into days from (select dt
from(
select to_date(:p1_from_date, 'DD-Mon-YYYY') + rownum -1 dt
from dual
connect by level <= to_date(:p1_to_date, 'DD-Mon-YYYY') - to_date(:p1_from_date, 'DD-Mon-YYYY') + 1)
where to_char(dt,'fmday') not in ('sunday','saturday') dual;
If the Dates is between from_date and To_date comes in Saturday and sunday , it should exclude and return the count(*) remaining dates,
For example,
If the From_date is 04-may-2012'
and To_date is 08-may-2012,
Here the dates 5th may and 6th may are "saturday" and "sunday"
Then the remaining dates are(excluding sat,sunday and dates in holiday_table),
04-may-2012,
07-may-2012
08-may-2012.
so
count(*)
3I am using the above code but still it returning 5,
I think this
..where to_char(dt,'fmday') not in ('sunday','saturday')
code is not working.
Can anyone help me to solve my Issue.
Hi theoa,
Actually this is my full code,
declare
days number(3);
ex_days emp_master.remaining_days%type;
new_rem_days emp_master.remaining_days%type;
begin
select count(*)
into days
from (select dt
from (select to_date (:p1_from_date, 'DD-Mon-YYYY',
'NLS_DATE_LANGUAGE=''english''')
+ rownum - 1 dt
from dual
connect by level <=
to_date (:p1_to_date, 'DD-Mon-YYYY',
'NLS_DATE_LANGUAGE=''english''')
- to_date (:p1_from_date, 'DD-Mon-YYYY',
'NLS_DATE_LANGUAGE=''english''')
+ 1)
where rtrim(to_char(dt,'fmDay', 'NLS_DATE_LANGUAGE=''english''')) not in
('Sunday','Saturday')
minus
(select holiday_start
from holiday_master)) dual;
apex_application.g_print_success_message := 'Hi '||:APP_USER||' '||'You are applied leave for'||' ' || days||' ' ||'days';
select remaining_days
into ex_days
from emp_master
where upper(emp_name) = upper(:APP_USER);
new_rem_days := ex_days - days;
update emp_master
set remaining_days = new_rem_days
where upper(emp_name) = upper(:APP_USER);
update leave_transaction
set remaining_days = new_rem_days
where upper(emp_name) = upper(:APP_USER)
and leave_id=
(select max(leave_id)
from leave_transaction);
end;The select statement which i mentioned above is working fine in database but not working in PAEX application.
Similar Messages
-
Calculate the number of days in a year excluding Saturday and Sunday
Hi All,
I need to get the number of days in a year excluding Saturday and Sunday for HR module and then subtract the public holidays.
Can some let me know how this needs to be done while loading data from one infocube to another.
Is there any Function module for the same so that i can write any start routines.
And also is there any table available for Tcode-SCAL with which i can write any start routines.
Kindly help me as soon as possible.
Regards,
KumarHi Harish
Refer to the screenshot for Import and Export parameters
Code
FUNCTION ZBI_FM_GET_HOLIDAYS .
*"*"Local Interface:
*" IMPORTING
*" VALUE(DATE_FROM) TYPE SCAL-DATE DEFAULT SY-DATUM
*" VALUE(DATE_TO) TYPE SCAL-DATE DEFAULT SY-DATUM
*" VALUE(FACT_CAL) TYPE SCAL-FCALID DEFAULT SPACE
*" VALUE(ONLYFACT_DAYS) TYPE CHAR1 OPTIONAL
*" EXPORTING
*" REFERENCE(HOLIDAYS) TYPE I
*" TABLES
*" DAY_ATTRIBUTES STRUCTURE CASDAYATTR
*" EXCEPTIONS
*" FACTORY_CALENDAR_NOT_FOUND
*" HOLIDAY_CALENDAR_NOT_FOUND
*" DATE_HAS_INVALID_FORMAT
*" DATE_INCONSISTENCY
DATA: LT_DAY_ATTRIBUTES TYPE TABLE OF CASDAYATTR WITH HEADER LINE.
DATA: LV_LINES TYPE SY-SUBRC.
DATA: DATE1 LIKE DATE_FROM,
DATE2 LIKE DATE_TO.
*if from date is gt to date then interchange the dates and multiply the result with -1.
IF DATE_FROM GT DATE_TO.
DATE2 = DATE_FROM.
DATE1 = DATE_TO.
ELSE.
DATE1 = DATE_FROM.
DATE2 = DATE_TO.
ENDIF.
CALL FUNCTION 'DAY_ATTRIBUTES_GET'
EXPORTING
FACTORY_CALENDAR = FACT_CAL
* HOLIDAY_CALENDAR = ' '
DATE_FROM = DATE1
DATE_TO = DATE2
LANGUAGE = SY-LANGU
* IMPORTING
* YEAR_OF_VALID_FROM =
* YEAR_OF_VALID_TO =
* RETURNCODE =
TABLES
DAY_ATTRIBUTES = LT_DAY_ATTRIBUTES
EXCEPTIONS
FACTORY_CALENDAR_NOT_FOUND = 1
HOLIDAY_CALENDAR_NOT_FOUND = 2
DATE_HAS_INVALID_FORMAT = 3
DATE_INCONSISTENCY = 4
OTHERS = 5 .
IF SY-SUBRC = 0.
IF ONLYFACT_DAYS = 'X'.
DELETE LT_DAY_ATTRIBUTES WHERE FREEDAY EQ SPACE.
ELSE.
DELETE LT_DAY_ATTRIBUTES WHERE WEEKDAY LT 6.
ENDIF.
DESCRIBE TABLE LT_DAY_ATTRIBUTES LINES LV_LINES.
HOLIDAYS = LV_LINES.
* IF DATE_FROM GT DATE_TO.
* HOLIDAYS = HOLIDAYS * -1.
* ENDIF.
ELSEIF SY-SUBRC = 1.
RAISE FACTORY_CALENDAR_NOT_FOUND.
ELSEIF SY-SUBRC = 2.
RAISE HOLIDAY_CALENDAR_NOT_FOUND.
ELSEIF SY-SUBRC = 3.
RAISE DATE_HAS_INVALID_FORMAT.
ELSEIF SY-SUBRC = 4.
RAISE DATE_INCONSISTENCY.
ENDIF.
ENDFUNCTION. -
How to jump (saturday and sunday) a task on friday to monday
hi
i had a 'long' task (2 days)
i need to begin friday
and end on monday
so, i w jump saturday and sunday
thks for your lightsso
ical/pref/days per week
it's useless
I am disappointed to see that implemented function is useless
...I will make with...
Tks ferd -
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 -
Hi All,
I have a simple query which is below:-
Declare @reportdate date
set @reportdate= (DATEADD(dd,-5,getdate()))
select * from dbo.Table
where date IN (@reportdate)
I need this query to pull the data for the last 3rd business day .So lets say today is monday then i need the data for last week wednesday which is 3 business days back from monday, if today is a tuesday it would be for last thursday ( as 3 business days for
tuesday would be thursday). But if today is wednesday then i need to be last 3rd business day which is last friday and i also need to get the data for saturday and sunday.
Can someone please help me how cani change my filter to do this?
Please let me know if i am still unclear.
ThanksHi SqlDev12,
Based on my understanding on your requirement, you can reference the below sample.
CREATE TABLE BusinessTable
Bdate DATE,
Wd VARCHAR(10)
;WITH Cte(DT,WD) AS
SELECT CAST('20150401' AS DATE),DATENAME(WEEKDAY,CAST('20150401' AS DATE))
UNION ALL
SELECT DATEADD(DAY,1,DT),DATENAME(WEEKDAY,DATEADD(DAY,1,DT)) FROM Cte
WHERE DT<GETDATE()
INSERT INTO BusinessTable SELECT * FROM Cte
SELECT * FROM BusinessTable
SET DATEFIRST 7 -- Set Sunday as the first day of a week
DECLARE @givenDay DATE ='20150415' --Wednesday
SELECT * FROM BusinessTable
WHERE Bdate BETWEEN
--For Monday and Sunday, select last wednesday
(CASE WHEN DATEPART(WEEKDAY,@givenDay) IN(1,2) THEN DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay)-1,0))
--For Tuesday and Wednesday, last week's Thursday and Friday
WHEN DATEPART(WEEKDAY,@givenDay) IN(3,4) THEN DATEADD(DAY,-5,@givenDay)
--For Thursday and Friday, current week's Monday and Tuesday
WHEN DATEPART(WEEKDAY,@givenDay) IN(5,6) THEN DATEADD(DAY,-3,@givenDay)
--For Saturday, current week's Wednesday
ELSE DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay),0)) END)
AND
(CASE WHEN DATEPART(WEEKDAY,@givenDay) IN(1,2) THEN DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay)-1,0))
WHEN DATEPART(WEEKDAY,@givenDay) IN(3) THEN DATEADD(DAY,-5,@givenDay)
WHEN DATEPART(WEEKDAY,@givenDay) IN(4) THEN DATEADD(DAY,-3,@givenDay)
WHEN DATEPART(WEEKDAY,@givenDay) IN(5,6) THEN DATEADD(DAY,-3,@givenDay)
ELSE DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay),0)) END)
DROP TABLE BusinessTable
If you have any feedback on our support, you can click
here.
Eric Zhang
TechNet Community Support -
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 ,
baluMore 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.. -
Billing date is for Monday for the orders created on Saturday and Sunday
Hi Friends,
I have an issue,that for the orders that are created on weekdays, the Billing date is for the same day.
But for the orders that are created on Saturday and Sunday,the Billing date is being determined automatically for Monday.
The goods are service material and ther is no delivery being created for these goods.Still the requested delivery date is being determined for Monday for the weekend orders.
Any idea where i can check these settings or which program or userexit can be looked into for this.
Thanks in advance...
Sultan KhanHi,
How about using BBP_DOC_CHANGE_BADI ?
Regards,
Masa -
Schedule line delivery date on saturday and sunday its confirm for monday
HI Experts
in cash sales process or normal OR also when i create sales order monday its work fine system take todays (current date) as delivery date and i can do delivery on same date
but if i create sales order on saturday system take coming monday as delivery date and give goods confirmation on monday date but iif i change manually system allow me to change the date for saturday and i can do delivery but i want it system should take delivery date as saturday (same date only )
because in my client there is no holiday all 365 as working day
in VOV8 its blank no lead time
factory calendor and logistic i define as all 7 days as working day
and sales org and plant i assign calendor
Please guide me where i miss and how can i solve this issue
thanks in advanceHi,
Check "OVLY" and "OVLZ" and If the sceduling is active for he shipping point /sales document type. Check "OVXD" and see If the Loading time/ Pick/pack time is determined from it. If they are getting determined from shipping point check the shipping point calender in "SCAL" .If it has saturday and sunday as holidays ,then you may have to change them. And check If the customer has goods recieving hours assigned to him (In customer master unloading point). If he has only 5 working days and If he accepts only goods at 8 am in the morining then system would propose like this.Kindly please let me know If you need any more Information on this.
Regards
Ram Pedarla -
Plan order is considering saturday and sunday as working day.
Hi All,
I have a problem where saturday and sunday is being conidered as working day when a plan order is created (Either manually or Automatically). But in calender assigned to this plant, saturday and sunday is assigned as holiday.
But when we convert the same plan order which has Saturday as Order start, the Basic start date of production order is moved to Firday.
EG. Plan order - XXXXXX has order finish date as 22-Aug-2011. Inhouse lead time is 2 days. So system takes 20-Aug-2011 as order srat date in plan order.
But when same Plan order is converted to Production order, then the Basic order start date is moved to 18-Aug-2011 and it says that 20-Aug-2011 and 21-Aug-2011 is maked as holiday in calender.
Can some one please suggest why is plan order considering Saturday and Sunday as working day.Hi,
Check the factory calendor assigned to plant which is referenced in plan order and teh factory calendor assigned to work center which is used in elad time scheduling in production order.. are they same?
Check how they ahve maintined..? -
Identifying Saturday and Sunday from calender dates
Hi all,
i have a table with all the date of year from 200 to till date.
now i want to identify all those dates from this table which are saturdays and sundays,
how can i do this?
please advice...
thanks.Depends on what the nls_territory parameter is set to:
alter session set nls_territory='UNITED KINGDOM';
select to_char(sysdate, 'd', 'nls_date_language=american') monday,
to_char(sysdate -1, 'd', 'nls_date_language=american') sunday
from dual;
M S
1 7
alter session set nls_territory='AMERICA'
select to_char(sysdate, 'd', 'nls_date_language=american') monday,
to_char(sysdate -1, 'd', 'nls_date_language=american') sunday
from dual;
M S
2 1Edited by: Boneist on 06-Jul-2009 12:01
BluShadow is too fast for me! -
Get a saturday and sunday dates
HI,
i need a days which are sunday and saturday, when i given a range of period i want to get days which are saturday and sunday within that range.
if any fm just suggest me.
Tahnks a lot.Hi,
Please find below an example on how to get the Weekend in shorttext, the dates and the total of weekend for the input date. I used only the FM ''DAY_ATTRIBUTES_GET'' . Please reward if you found useful. Thanks
REPORT zastest.
Data Declaration
TABLES : scal.
DATA : itab TYPE TABLE OF casdayattr,
wa_itab LIKE LINE OF itab.
DATA : l_line TYPE i,
l_wkend TYPE i.
Selection Screen
SELECT-OPTIONS p_date FOR scal-date.
START-OF-SELECTION.
CLEAR : l_wkend.
CALL FUNCTION 'DAY_ATTRIBUTES_GET'
EXPORTING
FACTORY_CALENDAR = ' '
HOLIDAY_CALENDAR = ' '
date_from = p_date-low
date_to = p_date-high
language = sy-langu
NON_ISO = ' '
IMPORTING
YEAR_OF_VALID_FROM =
YEAR_OF_VALID_TO =
RETURNCODE =
TABLES
day_attributes = itab
EXCEPTIONS
FACTORY_CALENDAR_NOT_FOUND = 1
HOLIDAY_CALENDAR_NOT_FOUND = 2
date_has_invalid_format = 3
date_inconsistency = 4
OTHERS = 5
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN '3'.
WRITE : 'Date has Invalid Format'.
when '4'.
WRITE : 'Date Inconsistency'.
WHEN '5'.
WRITE : 'Other exceptions'.
ENDCASE.
ELSE.
DESCRIBE TABLE itab LINES l_line.
IF l_line GT 0.
LOOP AT itab INTO wa_itab.
WRITE : / wa_itab-day_string.
CASE wa_itab-weekday.
WHEN '6'. l_wkend = l_wkend + 1.
WHEN '7'. l_wkend = l_wkend + 1.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
WRITE : / 'l_wkend - ', l_wkend.
ENDIF.
ENDIF.
END-OF-SELECTION.
Regards,
Loo -
Query to get holidays including saturday and sunday by giving month and year as input
query to get holidays including saturday and sunday by giving month and year as input.
Hi,
Create a table for holidays. You could INSERT one row for each holiday in each year, but it might be more useful if you just create 1 row for every day, with a column that tells whether that day is a holday, part of a weekend, or a work day.
See
http://forums.oracle.com/forums/message.jspa?messageID=3351081
for a user-defined function that tests if a given DATE is holiday.
You could use such a function when populating the table I mentioned earlier. -
Planned Delivery Time is included Saturday. and Sunday?
Dear Guru,
Please kindly advice me about Planned Delivery Time in Days in the MRP View.
Is it include Saturday and Sunday?
If my calendar is not work on Saturday and Sunday.
Thank you very much.
SaiyaSystem calculates with help of factory calender. if you maintaned saturday and sun day as public holidays then system will not considered for planned delivery time.
-
MF50 not able to book Capacity on Saturday and Sunday
Dear Experts,
In MF50 planning table the if we book requirement on Saturday and Sunday .we are abel to book the requirement but "Not yet assigned" is gyred out system is creating a back ward scheduling to friday.
In work Centre we maintained factory calender ( all the days are working) and shift sequence.
Please let me know the settings.
Regards
SandeepHi Sandeep,
Check your setting in T-code SCAL.
I think it might be require modification in days selection for Calender creation.
if any doubt then revert back.
Regards,
Mukesh.
Maybe you are looking for
-
Failure to install Windows XP Mode under Win7
After (apparently successful) installation of 500-megabyte "Windows XP Mode," installation of 10-megabyte "Windows Virtual PC," after reboot, reports "Failure configuring Windows updates / Reverting changes." Event viewer shows "Package KB958559 fail
-
Spry Validation Text Box - Playing Nicely w/ Javascript
Greetings- I'm using the Spry Validation Text Fields in a registration form I'm designing. I really like the validation they provide. However, I'm trying to get them to play nicely with a password validation Javascript code that gets called when the
-
Sync iPhone 5 with Outlook through iCloud
Hi, When trying to sync, I get the message from iCloud: "Setup can't continue because Outlook isn't configured to heva a default profile. Check your Outlook settings and try again." I did choose a default setting (Outlook) and i stille get the messag
-
I cannot find any example of successfully setting up, building and executing an Actionscript project in Flex Builder with the main class being in a package. I don't care if I have to create the appropriate directory structure manually, I just want to
-
ZEN MX 8GB: E-book, RSS options only in Chinese, not English
Just as the title says, on my ZEN MX 8GB, there are menu options for "e-books" and "RSS feed reader" that appear only when the player's language is set to Chinese. My firmware is up to date, so I know that's not the issue. Placing text or HTML docume