Count days

Hi experts,
i m looking for a fm or code for counting occurence of a day in period.
Example : I want to count the number of times that monday occurs in the period between begin date 01-01-2010 and end date
   31-12-2010.
So i have the input parameters : name of the day ( number of the day ). and begin and end period

Hi,
Please check this link will help you find your solution.
http://wiki.sdn.sap.com/wiki/display/ABAP/FunctionModulerelatedonDate+calculations
Cheers.

Similar Messages

  • Count days in a month for a date range

    i am trying to find no. of days between 2 Date Ranges for a list of Ids. i used the logic in the below link:
    count days of the month
    My query is giving duplicates since, I have list of Ids.
    Doctor_ID     Patient_ID     ARRIVE_DT_TM     DISCH_DT_TM
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45
    763305     42972232     1/7/2013 20:27     3/15/2013 19:15
    25391509     42972298     2/4/2013 22:45     3/8/2013 22:03
    746779     42972331     1/4/2013 23:00     3/26/2013 21:50
    763305     42972338     3/4/2013 22:19     3/6/2013 19:35
    763305     42972411     11/4/2013 22:32     3/29/2013 17:30
    I am looking for query to give me for Patient_ID = 42972229
    MONTH     COUNT_DAYS
    201210     14
    201211     30
    201212     31
    201301     31
    201302     28
    201303     14
    I am running the following code and it loops through the months and gives duplicates when I remove where Patient_id IN (42972229)
    select
    Doctor_ID
    , Patient_ID
    , AR_DTTM
    , DSC_DTTM
    , TO_CHAR(ADD_MONTHS(TRUNC(date1, 'MONTH'), LEVEL - 1), 'YYYY MM') MONTHS_BET
    , (LEAST(date2, ADD_MONTHS(TRUNC(date1, 'MONTH') - 1, LEVEL)) - GREATEST(date1, ADD_MONTHS(TRUNC(date1, 'MONTH'), LEVEL - 1)))+ 1 AS DAYSCOUNT
    from (select
    Doctor_ID
    , Patient_ID
    , ARRIVE_DT_TM AR_DTTM
    , DISCH_DT_TM DSC_DTTM
    ,TRUNC(ARRIVE_DT_TM,'DDD') AS date1
    ,TRUNC(DISCH_DT_TM,'DDD') AS date2
    from temp where Patient_id IN (42972229)
    CONNECT BY LEVEL <= MONTHS_BETWEEN(TRUNC(date2, 'MONTH'), TRUNC(date1, 'MONTH')) + 1
    Please help!

    Hi,
    ASTRA_007 wrote:
    Results I would like to see are:
    Doctor_ID     Patient_ID     ARRIVE_DT_TM     DISCH_DT_TM     Month     CountofDays
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2012 10     14
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2012 11     30
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2012 12     31
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2013 01     31
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2013 02     28
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2013 03     14
    763305     42972232     1/7/2013 20:27     3/15/2013 19:15     2013 01     25
    763305     42972232     1/7/2013 20:27     3/15/2013 19:15     2013 02     28
    763305     42972232     1/7/2013 20:27     3/15/2013 19:15     2013 03     15
    and so on...So each row represents a patient-month, and you want to display several columns from the temp table on each output row. In that case, include all those columns in both the SELECT and GROUP BY clauses, like this:
    WITH     universe     AS
         SELECT     *
         FROM     temp
    --     WHERE     patient_id     IN (42972229)
    ,     date_range     AS
         SELECT     TRUNC (MIN (arrive_dt_tm))     AS first_date
         ,     TRUNC (MAX (disch_dt_tm))     AS last_date
         FROM     universe
    ,     all_dates     AS
         SELECT     first_date + LEVEL - 1     AS a_date
         FROM     date_range
         CONNECT BY     LEVEL     <= (last_date + 1) - first_date
    SELECT    u.doctor_id
    ,       u.patient_id
    ,       u.arrive_dt_tm
    ,       u.disch_dt_tm
    ,       TO_CHAR ( TRUNC (a.a_date, 'MONTH')
                  , 'YYYY MM'
                )          AS month
    ,       COUNT (*)          AS count_days
    FROM       all_dates  a
    JOIN       universe   u  ON  a.a_date  BETWEEN  TRUNC (u.arrive_dt_tm)
                                         AND      u.disch_dt_tm
    GROUP BY  u.doctor_id
    ,       u.patient_id
    ,       u.arrive_dt_tm
    ,       u.disch_dt_tm
    ,         TRUNC (a.a_date, 'MONTH')
    ORDER BY  u.patient_id
    ,       TRUNC (a.a_date, 'MONTH')
    ;Output from your sample data (with no filtering):
    `DOCTOR_ID PATIENT_ID ARRIVE_DT_TM     DISCH_DT_TM      MONTH   COUNT_DAYS
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2012 10         14
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2012 11         30
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2012 12         31
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2013 01         31
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2013 02         28
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2013 03         14
        763305   42972232 1/7/2013 20:27   3/15/2013 19:15  2013 01         25
        763305   42972232 1/7/2013 20:27   3/15/2013 19:15  2013 02         28
        763305   42972232 1/7/2013 20:27   3/15/2013 19:15  2013 03         15
      25391509   42972298 2/4/2013 22:45   3/8/2013 22:3    2013 02         25
      25391509   42972298 2/4/2013 22:45   3/8/2013 22:3    2013 03          8
        746779   42972331 1/4/2013 23:0    3/26/2013 21:50  2013 01         28
        746779   42972331 1/4/2013 23:0    3/26/2013 21:50  2013 02         28
        746779   42972331 1/4/2013 23:0    3/26/2013 21:50  2013 03         26
        763305   42972338 3/4/2013 22:19   3/6/2013 19:35   2013 03          3
    In the end the objective is to count the no. of days in each month between the arrival and discharge dates by Physician and for his/her patients.Then is the output above really what you want? Say you're interested in physician 763305. That physician had 18-patient days in March, 2013, but the output doesn't make it clear.
    I ran your query, it works great but I have a long list of patients for whom I have to run these counts.the query above includes all patient_ids.
    That's a separate problem, to be solved in the first sub-query, universe. The rest of the query will be unchanged.
    How will you know which patients to include? If you can derive the list from temp itself, just use a WHERE clause in universe. If you need to look at other tables, join them in universe, or use them in sub-queries in universe, or both.
    For exmple, if you decide that the list of patient_ids has no pattern, and that you'll need to store their ids in a separate table (perhaps a global temporary table), then universe might be:
    WITH     universe     AS
         SELECT     t.*     -- or list columns needed
         FROM     temp                        t
         JOIN     patient_ids_to_include  p 
                      ON  p.patient_id = t.patient_id
    ) ...The rest of the query can be the same as above.
    If a same patient is admitted again then Patient_ID will be different no matter when readmitted.Are you saying that patient_id identifies a visit, not a patient, and that the same person is assigned a different patient_id every time that person is admitted?
    For
    INSERT INTO temp (doctor_id, patient_id, arrive_dt_tm, disch_dt_tm)
    VALUES ( 755722
    , 42972229
    , TO_DATE ('03/14/2013 23:00', 'MM/DD/YYYY HH24:MI')
    , TO_DATE ('04/01/2013 12:00', 'MM/DD/YYYY HH24:MI')
    First the Patient ID will be different from the earlier admission. Second the results will show like:
    Doctor_ID     Patient_ID     ARRIVE_DT_TM     DISCH_DT_TM     Month     CountofDays
    755722     42972229     3/14/2013 23:00     4/1/2013 12:00     2012 03     14
    755722     42972229     3/14/2013 23:00     4/1/2013 12:00     2012 04     1Are you saying that temp.patient_id is unique, and so the situation is impossible?
    Edited by: Frank Kulash on May 7, 2013 10:23 AM

  • Count Days in month

    Hi Team members,
    we are working on a budgeting application and stuck on below Research, please assist/advise is there any built-in Function to count Days in a Month which we can use or a work around .
    Requirement:
    To calculate budgeted Expenses per month, user will enter the daily budgeted expenses for a month and it will multiple with total number of days in a month via formula. same thing happens to some revenue items.
    Note:
    every months contains different number of Days which will result in change in Expense/Revenue figures.
    e.g
    Daily Expense for Jan will be $100/day
    total days in Jan = 31
    Result will be 31*100 = $3100 expense in Jan
    but in Feb it will be
    Daily Expense for Feb will be $100/day
    total days in Jan = 28
    Result will be 28*100 = $2800 expense in Feb
    Regards,
    Alee

    Dear Alp,
    Thanks for the Code!!!
    Note:
    In general terms the algorithm for calculating a leap year is as follows...
    A year will be a leap year if it is divisible by 4 but not by 100. If a year is divisible by 4 and by 100, it is not a leap year unless it is also divisible by 400.
    Thus years such as 1996, 1992, 1988 and so on are leap years because they are divisible by 4 but not by 100. For century years, the 400 rule is important. Thus, century years 1900, 1800 and 1700 while all still divisible by 4 are also exactly divisible by 100. As they are not further divisible by 400, they are not leap years.
    Regards,
    Alee

  • So, I got Adobe CC a year ago and I recently downloaded ABOBE CC 2014 at adobes SUGGESTION. When I open After effects it says I only have 4 (and counting ) days left to purchase----I'm supposed to get it for FREE, right?.  It doesn't happen when I open il

    So, I got Adobe CC a year ago and I recently downloaded ABOBE CC 2014 at adobes SUGGESTION. When I open After effects it says I only have 4 (and counting ) days left to purchase…………I’m supposed to get it for FREE, right?.  It doesn’t happen when I open illustrator and Photoshop CC 2014. Am I doing something wrong? If you’re not the one to contact please refer to the correct person……….the school uses AE CC 2014  so I NEED to have the correct version.

    you MAY need to log out of the Cloud and restart your computer and log back in to the Cloud for things to work
    or
    A chat session where an agent may remotely look inside your computer may help
    Creative Cloud chat support (all Creative Cloud customer service issues)
    http://helpx.adobe.com/x-productkb/global/service-ccm.html

  • Count days per month

    dear members,
    I have been provided with the date range.
    i want to calculate the no. of days for each month, within the above date range.
    e.g. date1='10-01-2011' and date2='18-03-2011'
    for month=01 count days=22
    for month=02 count days=28
    for month=03 count days=18
    thanks
    teefu
    developer

    WITH     parameters     AS
         SELECT     TO_DATE ( '10-01-2011'
                   , 'DD-MM-YYYY'
                   )     AS start_dt
         ,     TO_DATE ( '18-03-2011'
                   , 'DD-MM-YYYY'
                   )     AS end_dt
         FROM     dual
    SELECT     TO_CHAR ( start_dt + LEVEL - 1
              , 'FMMonth YYYY'
              )     AS month
    ,     COUNT (*)     AS days
    FROM     parameters
    CONNECT BY     LEVEL <= 1 + end_dt - start_dt
    GROUP BY TO_CHAR ( start_dt + LEVEL - 1
              , 'FMMonth YYYY'
    ORDER BY MIN (LEVEL)
    duplicate thread already one has given the above answer
    count days of the month
    Edited by: LPS on Jul 21, 2011 2:16 AM

  • FM to exclude holidays and weekends and count days in Leave period

    Hi Friends,
    My requirement is to count no of days leave applied !!
    Which should exclude Holidays and weekends and count only business days..
    I.E. per week onlyt 5 working days!!
    Is there any FM to do so Becasue this exlcuding holidays not happens manually...
    Thanks in advance...
    Regards
    sas

    Hi Dilek Please can you send the screen shots of those
    Just put HRworkdays F4 and can you send the screen shots of those please!!!Which will help to show to my client !!
    MY id is in businees card please take it as per rules i cant type ....Thanks in advance!!
    Regards
    sas
    Edited by: saslove sap on Sep 8, 2009 8:32 AM
    I have check with other client systems of ECC 6.0  there is no FM of you provided !! Intresting !!
    Any one any other idea to achieve the same please provide!!
    Regards
    sas
    Edited by: saslove sap on Sep 8, 2009 9:45 AM
    Edited by: saslove sap on Sep 8, 2009 10:04 AM

  • 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
    Jonas

    Hi 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

  • MDX count days - since registered (customer) - dynamically

    Hi, I have a problem with a MDX statement and I did not find an approach.
    We have a customer dimension that includes a date for the registration. We want to know following:
    How many days since the registration, but not only for the actual date (today), it must be dynamic.
    Example:
    Customer A registered on 2011-08-15 (yyyy-mm-dd).
    Whenwe choose the time dimension an we take the date 2011-08-20 we want the number 5 because he is registered since 5 days. When we choose 2011-08-25 the result would be 10 etc.
    It could be so easily: calculate the difference in days between Registration day and selected day ([Date].[Date].currentmeber????)
    Something like: datediff(days, [dim Customer].[Registration Date], [Date].[Date])
    But I´m to stupid to translate this easy problem to MDX. Any hints?

    EDIT: Fixed it (Forgot the date-dimension on axis 1) THANKS!
    Hi dstewartbi,
    your code looks not bad. Problem is: Only the actual date is not enough. I need something like currentMember. If I try this:
    WITH
    MEMBER [Measures].[Days Since Registration] AS
    ( StrToMember ( '[Dim Date].[Full Date Alternate Key].&[' + [Dim Customer].[Date Of Birth].CurrentMember.MEMBER_NAME + 'T00:00:00]' )
    : StrToMember ( '[Dim Date].[Full Date Alternate Key].&[' + [Dim Date].[Full Date Alternate Key].CurrentMember.Member_Name+ 'T00:00:00]' ) ).Count
    - 1
    I get following error:Cannot convert 'AllT00:00:00' into date-type
    If I just use:
    WITH
    MEMBER [Measures].[Days Since Registration] AS
    ( StrToMember ( '[Dim Date].[Full Date Alternate Key].&[' + [Dim Customer].[Date Of Birth].CurrentMember.MEMBER_NAME + 'T00:00:00]' )
    : [Dim Date].[Full Date Alternate Key].CurrentMember ).Count
    - 1
    I get the error (in german): "Operanden des Bereich (:) haben unterschiedliche Ebenen, müssen jedoch identisch sein"
    Something like Operands have different levels.

  • PCL 1: What is ANZHL & ANZHL1 & how to count days taken

    hi experts,
    I have question to understand PCL1. I want to check check all the annual leave types using in
    infotype 2001 for this year. However when I check table purl, fields anzhl show all the leave
    has been taken, include off day. For example I have taken leave 01/04/2010-6/04/2010.Actual date 05/04 is
    off day. However in fields anzhl, it will count 6 days(include off day). When I check fields anzh1
    it show 9 for every single day except 05/04. On 05/04, it show 0. What does it means actually,
    can I assume 0 in anzh1 as off day. How about 9?

    HI,
    0 and 9 must be the planned working hours from DWS on those respective days. Please cross check.
    cheers
    AJ

  • 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..

  • DP91 UOm to be day

    Dear all,
    We want to have DP91 (automatic billing) for one of our dept. The timesheets are interfaced with the WBS element of sales oder (time sheets are entered to the WBS activities by the associates). My problem is that when we are trying to run DP91 its taking the hours but we wanted to count days such that if an associate enters the timesheet for even one minute in a day it should be counted as a day for him.. Even we have put the UOM as u2018dayu2019 for the materials but in DP91 its appearing as hours.
    How to solve this problem.
    Regards,
    Padmaja

    Hi,
    I could understand from your question that You need to convert resources' hours in days.
    Please go to MM02-enter material no,organizational data and select views.You get material in change mode.Press on additional data button on application tool bar and select unit of measurement views.
    enter conversion unit on this screen.
    For example -If you consider 1  working day is 8 hours,maintain 1 day equal to 8 hours.
    If consultant enter 2 hours then it will be converted as 0.25 day.
    (Moreover you need to create WBS element for each consultant.I suggest you discuss your requirement with your MM consultant to help you.)
    Thanks,
    Vrajesh

  • Count consecutive Workdays where employee has taken SICK leave

    I am trying to identify a way within sql to count the number of consecutive workdays (Monday - Friday) an employee has taken SICK leave. My problem in the past has been trying to count days whereas we cross the weekend. Currently I have 4 queries identifying patterns around the weekend that I run and export into an Excel Spreadsheet and manipulate from there. My goal is to be able to list an EMPLID (employee id), EMPL_RCD ( employee record), Min(DUR) (Date of absence), Max(DUR), and count of consecutive workdays.
    Any help or guidance would will be appreciated. I have attached my current query.
    I run my current query 4 times using the patterns below one at a time.
    SELECT DISTINCT A.EMPLID,A.EMPL_RCD, A.DUR,b.dur,c.dur,d.dur, A.TL_QUANTITY, A.TRC
    FROM PS_TL_RPTD_TIME A, PS_TL_RPTD_TIME B, PS_TL_RPTD_TIME C,PS_TL_RPTD_TIME D
    WHERE A.EMPLID = B.EMPLID
    AND A.EMPL_RCD = B.EMPL_RCD
    AND A.EMPLID = C.EMPLID
    AND A.EMPL_RCD = C.EMPL_RCD
    AND A.EMPLID = D.EMPLID
    AND A.EMPL_RCD = D.EMPL_RCD
    AND B.EMPLID = C.EMPLID
    AND B.EMPL_RCD = C.EMPL_RCD
    AND B.TRC = C.TRC
    AND A.TRC = B.TRC
    AND A.TRC = C.TRC
    AND A.TRC = D.TRC
    AND (B.DUR = A.DUR+3 AND C.DUR = A.DUR+4 AND D.DUR = A.DUR+5) Friday, Monday, Tuesday, Wednesday
    AND (B.DUR = A.DUR+1 AND C.DUR = A.DUR+4 AND D.DUR = A.DUR+5) Thursday, Friday, Monday, Tuesday
    AND (B.DUR = A.DUR+1 AND C.DUR = A.DUR+2 AND D.DUR = A.DUR+5) Wednesday, Thursday, Friday, Monday
    AND (B.DUR = A.DUR+1 AND C.DUR = A.DUR+2 AND D.DUR = A.DUR+3) -- Same workweek
    AND A.TRC LIKE 'SICK%'
    AND NOT EXISTS ( SELECT 'x' FROM PS_JOB J
    WHERE J.EMPLID = A.EMPLID
    AND J.EMPL_RCD = A.EMPL_RCD
    AND J.EMPL_STATUS IN ('P','L')
    AND J.EFFDT = ( SELECT MAX(J1.EFFDT) FROM PS_JOB J1
    WHERE J1.EMPLID = J.EMPLID
    AND J1.EMPL_RCD = J.EMPL_RCD
    AND J1.EFFDT <= D.DUR))

    You should consider a technique from data warehousing where you use a table to describe dates. To keep things simple, let's create a table that holds all your valid business days for the past 2 weeks...
    create table business_dates (business_day date);
    begin
    insert into business_dates values (to_date('16-oct-2006'));
    insert into business_dates values (to_date('17-oct-2006'));
    insert into business_dates values (to_date('18-oct-2006'));
    insert into business_dates values (to_date('19-oct-2006'));
    insert into business_dates values (to_date('20-oct-2006'));
    insert into business_dates values (to_date('23-oct-2006'));
    insert into business_dates values (to_date('24-oct-2006'));
    insert into business_dates values (to_date('25-oct-2006'));
    insert into business_dates values (to_date('26-oct-2006'));
    insert into business_dates values (to_date('27-oct-2006'));
    insert into business_dates values (to_date('30-oct-2006'));
    insert into business_dates values (to_date('31-oct-2006'));
    insert into business_dates values (to_date('01-nov-2006'));
    insert into business_dates values (to_date('02-nov-2006'));
    insert into business_dates values (to_date('03-nov-2006'));
    end;
    now we create a table that shows whether each employee was sick or not for a given work day...
    create table attendance (empid number, business_day date, sick char(1));
    insert into attendance values (100, to_date('16-oct-2006'), 'N');
    insert into attendance values (100, to_date('17-oct-2006'), 'Y');
    insert into attendance values (100, to_date('18-oct-2006'), 'Y');
    insert into attendance values (100, to_date('19-oct-2006'), 'N');
    insert into attendance values (100, to_date('20-oct-2006'), 'N');
    insert into attendance values (100, to_date('23-oct-2006'), 'Y');
    insert into attendance values (100, to_date('24-oct-2006'), 'Y');
    insert into attendance values (100, to_date('25-oct-2006'), 'Y');
    insert into attendance values (100, to_date('26-oct-2006'), 'N');
    insert into attendance values (100, to_date('27-oct-2006'), 'N');
    insert into attendance values (100, to_date('30-oct-2006'), 'N');
    insert into attendance values (100, to_date('31-oct-2006'), 'Y');
    insert into attendance values (100, to_date('01-nov-2006'), 'N');
    insert into attendance values (100, to_date('02-nov-2006'), 'N');
    insert into attendance values (100, to_date('03-nov-2006'), 'N');
    insert into attendance values (105, to_date('16-oct-2006'), 'Y');
    insert into attendance values (105, to_date('17-oct-2006'), 'Y');
    insert into attendance values (105, to_date('18-oct-2006'), 'N');
    insert into attendance values (105, to_date('19-oct-2006'), 'N');
    insert into attendance values (105, to_date('20-oct-2006'), 'Y');
    insert into attendance values (105, to_date('23-oct-2006'), 'N');
    insert into attendance values (105, to_date('24-oct-2006'), 'N');
    insert into attendance values (105, to_date('25-oct-2006'), 'Y');
    insert into attendance values (105, to_date('26-oct-2006'), 'Y');
    insert into attendance values (105, to_date('27-oct-2006'), 'Y');
    insert into attendance values (105, to_date('30-oct-2006'), 'Y');
    insert into attendance values (105, to_date('31-oct-2006'), 'Y');
    insert into attendance values (105, to_date('01-nov-2006'), 'N');
    insert into attendance values (105, to_date('02-nov-2006'), 'N');
    insert into attendance values (105, to_date('03-nov-2006'), 'Y');
    Now the query to get each sick occurrence and the number of consecutive days for each employee is...
    select empid, first_sick_day, sick_count from
    (select empid,
    first_value(business_day) over (partition by empid, groupno order by business_day) as first_sick_day,
         row_number() over (partition by empid, groupno order by business_day) as rn,
    count(*) over (partition by empid, groupno) as sick_count
    from
    (select empid, business_day, daynum-rownum groupno
         from
              (SELECT a.empid, a.business_day, d.day_num as daynum
                   FROM attendance a,
                        (select rownum as day_num, business_day
                        from (select business_day from business_dates order by business_day)) d
                   WHERE sick = 'Y' AND a.business_day = d.business_day
                   ORDER BY 1,2 )
    where rn = 1;
    The above query can be modified slightly to only give you the sick occurrence with the maximum number of consecutive days for each employee.
    Having a separate date table is nice because you can take in account weekends, holidays or any other nonwork day by just removing that date from the table. Generating this table is easy as date dimension examples can be found on on the web, and the amount of rows is small (250 rows per year approx).
    JR

  • Need to display date result but has to exclude sat & sun day

    Hi all,
    I need to display date (A), from the plan date (B) for qty more than 10, but the result of A, should be B -10 and should not include sat & sunday.
    I managed to do in excel but I have problem in oracle sql here.
    My quote in excel, =IF(qty<=10, WORKDAY(plan_date,-5), WORKDAY(plan_date,-10))
    If qty=12, plan_date is 30/05/11, the result is 16/05/11
    qty=2, plan_date is 30/05/11, the result is 23/05/11
    Anyone can help me to quote in SQL ?
    Thanks.
    Lim

    CREATE OR REPLACE FUNCTION GOKHAN.business_date (start_date DATE, days NUMBER)
       RETURN DATE
    IS
       counter  number := 0;
       curdate DATE:= start_date;
    BEGIN
       WHILE counter < days
       LOOP
          curdate := curdate  - 1;
          IF TO_CHAR (curdate, 'D') BETWEEN 1 AND 5
          THEN
             dbms_output.put_line( curdate || ' ' || TO_CHAR (curdate, 'D'));
             counter := counter + 1;
          END IF;
       END LOOP;
       RETURN curdate;
    END;
    with t as (
    select to_date('30/05/11','DD/MM/YY' ) plan_date, 12 qty from dual
    union all
    select to_date('30/05/11','DD/MM/YY' ) , 2  from dual
    select qty, case when qty <= 10 then business_date( plan_date, 5 ) else business_date( plan_date, 10 ) end plan_date from t;
           QTY PLAN_DATE
            12 16/05/2011
             2 23/05/2011Best Regards,
    Gokhan Atil
    If this question is answered, please mark appropriate posts as correct/helpful and the thread as closed. Thanks

  • Get working days of actual month in time management

    Hello,
    a customer wants his employees to work some additional time every workday. The time is different for each employee and has to be specified on a monthly basis, but has to be shown daily in time sheet.
    Days with holidays or illness do not require additional work, but count when calculation daily quota.
    I would like to use P0050-ZTZUA to store the value of the hours which the employee has to work extra per month.
    Now I need to divide this value through the number of workdays of the actual month, to get a value per day. Unfortunately I did not find any operation to get number of workdays.
    Thanks in advance

    Hello again.
    I did not get it!
    I made a simple PCR "Z123" just to test, how to count days. It looks like this:
               D VARSTCURMO
    **           HRS=1     ADDDB9082
    I call this with ACTIO Z123 and see, that the result for timetype 9082 is 1 at every day that is evaluated in my calculation period.
    In the example I do not care for workingdays, I just wanted to test, if the counting of days is functioning.
    Since the timetype 9082 is cumulated, I get number of days of period at the end of the time calculation in SALDO-Table.
    For example:
    Day               Saldo in 9082
    January  1             1
    January  2             2
    January  3             3
    January 31            31
    My problem is, that I need the number of days at each day of the calculation. Already at January 1 I need to divide a given amount of time through the number of days (31 in the example).
    I'm afraid, that this issue cannot be solved?

  • ICal custom repeat every x days EXCLUDING weekends?

    I have an event I would like to repeat every x number of days excluding weekends (so only counting M-F as "counted" days). Is there a way to do this?

    You can exclude Sat/Sun, but they will still be counted - so an occurrence on those days is dropped, and you will get fewer occurrences than you should.
    AK

Maybe you are looking for