How to calculate the date fields while excluding Saturday and Sunday

Hi, I use Jdeveloper 11.1.3.4

I have an Oracle database and creates a table called holiday with 3 attributes:


user (VARCHAR)

(early)

end (date)


The idea is that you subtract the finish from the beginning and get a number of vacation days used. The thing is that the sum should exclude Saturday and Sunday.

Any way to do it?
/* Formatted on 6/1/2011 7:57:32 AM (QP5 v5.149.1003.31008) */
WITH t AS (  SELECT id,
                    MAX (strt) strt,
                    MAX (finish) finish,
                    SUM (dys) days_off
               FROM (SELECT id,
                            strt,
                            finish,
                            CASE
                               WHEN TO_CHAR (dy, 'day') LIKE 'saturday%' THEN 0
                               WHEN TO_CHAR (dy, 'day') LIKE 'sunday%' THEN 0
                               ELSE 1
                            END
                               dys
                       FROM vacations
                     MODEL
                        PARTITION BY (ID id)
                        DIMENSION BY (0 d)
                        MEASURES (POCETAK strt, KRAJ finish, POCETAK dy)
                        RULES
                           (dy [FOR d FROM 1 TO finish[0] - strt[0] INCREMENT 1] =
                                 (NVL (dy[CV () - 1], dy[CV ()]) + 1)))
           GROUP BY id
           ORDER BY id)
SELECT t.id,
       t.strt,
       t.finish,
       t.days_off,
       vacations.korisnik,
       SUM (
          CASE
             WHEN finish < TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off
             ELSE 0
          END)
       OVER (PARTITION BY vacations.korisnik ORDER BY t.id)
          this_years_running_total,
       SUM (
          CASE
             WHEN finish < TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off
             ELSE 0
          END)
       OVER (PARTITION BY vacations.korisnik)
          this_years_grand_total,
       SUM (
          CASE
             WHEN finish >= TO_DATE ('01/07/2011', 'dd/mm/yyyy')
             THEN
                days_off
             ELSE
                0
          END)
       OVER (PARTITION BY vacations.korisnik ORDER BY t.id)
          next_years_running_total,
       SUM (
          CASE
             WHEN finish >= TO_DATE ('01/07/2011', 'dd/mm/yyyy')
             THEN
                days_off
             ELSE
                0
          END)
       OVER (PARTITION BY vacations.korisnik)
          next_years_grand_total
  FROM t, vacations
 WHERE t.id = vacations.id
id                    strt               finish        daysoff          korisnik    thisyrruntot  thisyrtot   netyrruntot    nextyrtotal
1     5/25/2011     5/31/2011     5     Kantardzic     5     22     0     26
2     6/6/2011     6/13/2011     6     Kantardzic     11     22     0     26
5     6/1/2011     7/6/2011     26     Kantardzic     11     22     26     26
6     6/16/2011     6/30/2011     11     Kantardzic     22     22     26     26

Tags: Database

Similar Questions

  • How to exclude "Saturday" and "Sunday" in APEX 4.1 count (*)

    Hi everybody using APEX 4.1.

    The Leave_transaction Table contains the following fields,
    1.Leave_id
    2.Emp_name
    3.From_date
    4.To_date
    5.Remaining_days

    The Emp_Master Table contains 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 date is between from_date and To_date comes Saturday and Sunday, it must exclude, return the count (*) rest of dates,
    For example,.

    If the From_date is 04-may-2012'
    and To_date is 08-may-2012,

    Here the dates 5 May and 6 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(*) 
     3
    I use the code above but it return 5.
    I think that this

    .. To_char (dt, 'fmday') if not in ('Sunday', 'Saturday')

    code does not work.
    Can someone help me solve my problem.

    Gurujothi wrote:
    Great salvation,

    select to_char(to_date('20120506','yyyymmdd'), 'fmday') from dual;
    

    back on Sunday.

    No it's not. You may have typed fmDay? The format is case-sensitive.

    sql> select to_char(to_date('20120506','yyyymmdd'), 'fmday') from dual;
    
    TO_CHA
    ------
    sunday
    
    sql> select to_char(to_date('20120506','yyyymmdd'), 'fmDay') from dual;
    
    TO_CHA
    ------
    Sunday
    
  • How to calculate the date from sysdate


    I try to get 12/09/2009-12:51:30 by subtracting the current date to sysdate.

    I can get with this year, but I don't know how I can get to the date and the month preceding.

    () Choose add_months (sysdate-36() of double) = 12/09/2010

    Planned result 12/09/2010 13:23:30

    Thank you for the help

    I'm assuming that time is fixed if it is to see the example below.

    SQL > select add_months (to_date (to_char(sysdate,'dd-mon-yyy') |)) (("" 12:51:30 ',' dd-MON-yyy hh: mi: ss AM "), - 36) prior_date
    2 double;

    PRIOR_DATE
    -----------------------
    12 - Oct - 2010 12:51:30

    SQL >

  • How to calculate the date interval

    Hi Experts,

    I'm looking for a way to calculate the interval between two dates. And get the result to the format "dd.mm.yyyy hh24:mi:ss.
    select  sysdate - to_date('1.1.2000 12:00:00','dd.mm.yyyy hh24:mi:ss') from dual
    Best practices for a problem like this?

    Best regards
    Igor
    select trunc( months_between( day2, day1 ) / 12 ) years
         , mod( trunc( months_between( day2, day1 ) ), 12 ) months
         , numtodsinterval( day2 - add_months( day1, trunc( months_between( day2, day1 ) ) ), 'DAY' ) rest
    from ( select to_date( '19-01-1979', 'dd-mm-yyyy' ) day1, sysdate day2 from dual )
    
  • How to calculate the data according to the fiscal

    I want to dispaly the result for  the accounting year from April to March for any accounting year (Accounting year is from April to March). 
    I have a table INVOICE. 
    
    CREATE TABLE INVOICE
    (
      IN_NO       NUMBER,
      IN_DT       DATE,
      IN_DETAILS  VARCHAR2(20 BYTE)
    )
    
    I want to calculate display the result for accounting year from April 2010 to March 2011, and from April 2011 to MArch 2012.
    What statement should i use to filter the data as above ?
    
    Sanjay

    user12957777 wrote:

    I want to dispaly the result for  the accounting year from April to March for any accounting year (Accounting year is from April to March).
    I have a table INVOICE. 
    
    CREATE TABLE INVOICE
    (
    IN_NO       NUMBER,
    IN_DT       DATE,
    IN_DETAILS  VARCHAR2(20 BYTE)
    )
    
    I want to calculate display the result for accounting year from April 2010 to March 2011, and from April 2011 to MArch 2012.
    What statement should i use to filter the data as above ?
    
    Sanjay
    

    You should now learn to use correctly

     tags
    
    select to_char(add_months(in_dt,-3),'YYYY') FISCAL_YEAR FROM INVOICE;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
    
  • How to display the date suffixes st, nd, rd and th for different days

    Hi all

    My first post here, please bare with me if I did not follow all of the guidelines, please report if there is.

    My question is how would you present the suffix that goes hand in hand with a certain day of the month.

    For example, st for the 1st of the month, nd for the 2nd and so on...

    My first thought is a table of rules which adds the relevant suffix based on the value of the day.

    Someone at - it other ideas.

    Thanks in advance.

    Thanks for the replies.

    for the moment, it is only limited to a single date, and I need actually just show the day, not the entire date, so I just used a table of rules.

    very of the suggestions, though, so thanks for your help.

  • days between two dates, excluding Saturday and Sunday

    Hello
    I have an obligation as: there are two entries in the query 1) startdate and 2) end date when the end user enter the start date and end date of the sql query to retrieve the number of days between given dates of beginning and end, and it should be retrivied with two condition 1) every Sunday between the above dates excluded 2) second and fourth Saturday of the month between the start dates and should be excluded.
    example of start date: 01-May-09
    end date: 16-May-09

    release date: 13

    SELECT COUNT (*)
    (SELECT TO_DATE('01-may-09') + LEVEL - dates 1)
    OF THE DOUBLE
    CONNECT BY LEVEL<= (to_date('16-may-09')="" -="" to_date('01-may-09'))="" +="" 1)="">
    WHERE ((TO_CHAR (inner.dates, 'd') = 7
    AND TO_CHAR(inner.dates, 'W') NOT IN (2, 4)
    )
    GOLD TO_CHAR (inner.dates, 'd.') not in (1.7)
    );

  • How to get the date between two dates, except Saturday 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 query above returns 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/2012
    Here, I need to exclude Dates that lights up "Saturday" and "Sunday" and also the joint birthday party
    Here it is May 1, 2012 "and I need the output as follows,
    04/25/2012
    04/26/2012
    04/27/2012
    04/30/2012
    05/02/2012
    05/03/2012
    05/04/2012
    I need the current request to calculate between two dates.
    Can anyone suggest me?

    Thank you
    Regsrds,
    gurujothi
    select dt
    from(
        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
            )
    where to_char(dt,'fmday') not in ('sunday','saturday')  
    

    To exclude, common holiday, you must have a host table. Then use an OUTER JOIN NOT IN or NOT EXISTS

  • How can I automatically populate the date field after only one "digitally signs" a .pdf form? Help, please! Thank you!

    How can I automatically populate the date field after only one "digitally signs" a .pdf form? Here's a sample:

    _ Digital Signature___ (signs), Date (Auto-remplit)

    Under field properties of the signature on the signature tab, you can use a custom script, like this:

    this.getField("Date").value = util.printd ("mm/dd/yyyy", new Date());

    You know, however, that a digital signature always displays the date and time, it has been applied?

  • How to calculate the sum of two digital form fields based on the selection of the checkbox.

    I have a form in Acrobat Pro who needs a custom calculation. How to calculate the sum of two digital form fields based on a selection of the checkbox. I have three number fields. Field-A and B are simple one or two digits. Field-C is the sum, or the total field. I want to field-C have a control box which, when turned on and off, just gives a. gives the sum of A + B

    _ Field - 2

    _ Field - A 4

    [check] _ _ field - 6 C

    [disabled] _ _ field - 2 C

    Thank you

    The custom field C calculation script could be:

    (function () {
    
        // Get the values of the text fields, as numbers
        var v1 = +getField("A").value;
        var v2 = +getField("B").value;
    
        // Set this field's value based on the state of the check box named "CB"
        if (getField("CB").value !== "Off") {
            event.value = v1 + v2;
        } else {
            event.value = v1;
        }
    
    })();
    

    Replace 'A', 'B', and 'CB' with the real names of the fields.

  • How to calculate the number of days/weeks/months between 2 dates?

    Hello

    I would like to know how to calculate the number of days/weeks/months between 2 dates in OBIEE 11 g, for example, I have 26/05/2013 and 19/05/2013, then I want to get 7 days.

    Thank you!
    Jamie

    Hi Jamie,

    Through this links...

    http://www.bravesoft.com/blog/?p=682
    http://twobiee.blogspot.in/2012/01/working-with-date-differences.html

    Mark as correct it allows u...
    Thank you...

  • calculate a date field first of the month

    I need to calculate a date field using date of hire as a base date, and it should return the first of the month following 30 days of date of hire.  (date of rental + 30 days then first of the month following that date).

    Hello margery497,

    In this scenario, you can create a text field 1 with validation as a calculated field and can add now() formula inside. Then, in the text field 2, you can add the now() + 30 formula and save it with the calculated field.

    Here is the reference for validating field:

    http://helpx.Adobe.com/EchoSign/KB/form-fields---validations.html

    Kind regards

    -Usman

  • How to replace a "null" in the date field to zero

    Hi guys,.

    I'm a lil stuck with this problem.
    I have a requirement where I need to replace a null value in the date field to zero.
    For example,.

    Cancel_date Cancel_date
    20120301 20120301
    20120908 20120908
    value null-> > > > > 0


    Thank you
    Anita

    Hi, Anita,.

    0 is not a DATE, so you cannot view it in a DATE column.
    There is no '0' display problem in a VARCHAR2 column, so use TO_CHAR to display dates, even if the default format, it's exactly what you want.

    SELECT     NVL ( TO_CHAR (date_column, 'YYYYMMDD')
             , '0'             -- or '       0', if you want it right-justified
             )          AS date_string
    FROM     table_x
    ;
    

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • Problems while extracting the hours of the Date field

    Hi guys,.

    We hope that you do well.

    I am facing some problems during extraction of the hours of the date field. Here is an example of my orders table:-

    Select * from orders;

    Arrival time of Order_NO product name
    1 computer Office November 20, 10 10:10
    2 November 21, 10 17:26:34 portable
    3 22 January 11 printer 08:10

    Earlier, it is stated that the daily number of orders take place in the roll of the order, I used to write a query

    arrival_time > = trunc ((sysdate-1), 'DD')
    and arrival_time < trunc ((sysdate), 'DD')

    The above query gives me yesterday how many orders have been been held.

    Now I have the new requirement to report on every 4 hours the number of orders will be held. For example if the current time is 08:00 IST then the query must extraction from 04:00 until 08:00 how many orders took place. The report will take place at 12:00 IST which will give me an order took place from 08:00 until 12:00.

    The report will be run every 4 hours per day and generate report of orders taken place for the past 4 hours. I have a programmer who will run this query every hour, but how to understand to get the order at the request of details who arrived for the past 4 hours. I'm not able to do this using trunc.

    Can you please help me how to make this happen. I checked "Extract" also, but I am not convinced.

    Help, please.

    Thanks in advance
    Aalami

    try something like

    with testdata as (
      select sysdate - level/24 t from dual
      connect by level <11
    )
    
    select
      to_char(sysdate, 'DD-MM-YYYY HH24:MI:SS') s
    , to_char(t, 'DD-MM-YYYY HH24:MI:SS') t from testdata
    where
    t >= trunc(sysdate, 'HH') - numtodsinterval(4, 'HOUR')
    
    S     T
    19-06-2012 16:08:21     19-06-2012 15:08:21
    19-06-2012 16:08:21     19-06-2012 14:08:21
    19-06-2012 16:08:21     19-06-2012 13:08:21
    19-06-2012 16:08:21     19-06-2012 12:08:21
    

    trunc (, 'HH') truncates the minutes and the seconds of the date.
    Extract the hour only works on timestamps
    concerning

    Published by: chris227 on 19.06.2012 14:13

  • How to fill my date fields placed on the Master Page to several pages?

    I have a dynamic form with fields flowing. I inserted date fields using the tab of Master Pages in Adobe LiveCycle Designer ES2, Windows 7 operating system. I have only 1 Master Page. Everything on the form works fine, except when I have several pages, date fields are empty on all except the first page. One of the date fields in the event javascript has exit to calculate the second field. I can manually change the fields of date subsequent page (s), but I don't want the end user to have to do. I want that date fields on the new pages to match the date fields in the first pages. Here's my output with notes to provide a visualization of what I'm looking for.

    IM Question.png

    Thank you very much in advance for anyone who can help me with this problem!

    Caroline

    You set the binding of the two fields date to the ' global mandatory?

    Important each of these fields need to own a meaningful name, for example "date_UserEntry" and "date_Calculate".

Maybe you are looking for