Calculate the interval in days

Hi all!

I need your help.

I have an oracle sql table.

This is going to...

TABLENAME: RACE
DATE NAME
JANUARY 11, 12 JAMES
JAMES JANUARY 12, 12
JAMES JANUARY 14, 12
JAMES JANUARY 17, 12
JAMES 22 JANUARY 12

1 FEBRUARY 12 JOHN
FEBRUARY 11, 12 JOHN
JOHN 13 FEBRUARY 12
JOHN 14 FEBRUARY 12
28 FEBRUARY 12 JOHN
JOHN 1ST MARCH 12

HOW can I calculate the date total interval (difference) for James and John in days?
for example in this case total is 7 days for James (January 11, 12 to 12 January 12 is 0 days and 12 January 12 to January 14, 12 is 1 day and 14 January 12 to 17 January 12 is 2 days) and 24 days for John

Data for the date will be random and can be up to names and dates of difference 60 so I would like to calculate all the names of different... Thank you!

Is there anyway that I can query without listing all the date?

Yes, just use the lower part of the "Real application" comment, that is:

select max(dt)-min(dt)-count(*)+1 diff
,      nm
from   race
group by nm;

I used the WITH only clause to generate some testdata...

Tags: Database

Similar Questions

  • Calculate the number of days remaining until the next anniversary. Help, please!

    Hi guys,.

    I'm new to the forum and to the development of BB. So please do not judge harshly if the answer to my question seems obvious.

    I need to calculate the number of days until the next birthday (taking into account any valid birth date)

    After looking at the API and the forum search, I realized that I could

    calculate the difference between two dates in milliseconds and then divide the delta of the value of a day in milliseconds. That is to say:

    birthdayCalendar.set (Calendar.YEAR, those);

    Date1 = birthdayCalendar.getTime () .getTime ();

    date2 = System.currentTimeMillis ();

    Delta = date1 - date2

    numOfDays = delta\DateTimeUtilities.ONEDAY

    Here's my question. How do I create a valid date1 what about leap years?

    Maybe there's a better way to solve this problem?

    Any help is greatly appreciated.

    I agree that the determination of the number of days between today and Feb. 29 could be a little difficult, if it is not a leap year.  I suspect that the calendar has a certain built-in mechanism to compensate for this, but your solution to choose a date is better.

    DST has a role to play, and Yes, the calendar makes up for it.  Let us take two dates, for example (before DST) March 1 and June 1 (after the DST).  If you take a calendar and set the same hour, minute, etc., they are all the same except for dates, then subtract one from the other, and then divide by the number of milliseconds in 1 hour, you calculate the number of hours between the same time on two different days.  You will find that it is not a multiple of 24 hours - because there is actually an hour less than the number of days since the clocks move forward (in the northern hemisphere anyway...),

    In your case, you are not calculating the number of hours, you calculate the number of days.  But you will be dividing by [24 * (time in an hour)].  If you take [23 * (time in an hour)] and divide it by [24 * (time in an hour)], using arithmetic on integers, you will end up 0.  The easiest to get around this, who also works for the end of the DST too, is to simply add one hour to the date before the division.

    Hope that makes sense...

  • PL/SQL function to calculate the non-working days

    Hello

    I have the following pl/sql function which generates a number of days between two selected dates (i.e. excluding weekends). However, I also need to exclude specific holidays - day of Christmas etc. These holiday dates are stored in a table in our database (11 GR 2) called "HOLIDAY".

    How can I integrate the holidays which is held in the table of holidays in the following query to exclude these dates as well? I know how to write a separate funtion pl/sql for a number of days between two dates using SELECT... BUT I can't work out how to bring together them in a single query.

    Could someone show me how with the pl/sql / dates below please?

    Example of HOLIDAY table below.

    Thank you!

    TP

    create or replace
    function WORKING_DAYS (pi_start_date in date, pi_end_date in date) return integer
    
    is
    
    v_start_date date :=pi_start_date;
    v_end_date date:=pi_end_date;
    v_count integer:=0;
    
    begin
    
    while v_start_date <= v_end_date
          loop
                            if to_char(v_start_date,'D') not in ('6','7')                    
                            then
                            v_count := v_count+1;                       
                            end if;
                           
                    v_start_date:=v_start_date+1;
                   
          end loop;
         
    return v_count;
    
    end;
    
    

    (select '10-Apr-2013' as NWD from dual union all
    select '06-May-2013' from dual union all
    select '27-May-2013' from dual union all
    select '26-Aug-2013' from dual union all
    select '26-Dec-2013' from dual union all
    select '25-Dec-2013' from dual union all
    select '01-Jan-2014' from dual union all
    select '18-Apr-2014' from dual union all
    select '21-Apr-2014' from dual union all
    select '05-May-2014' from dual union all
    select '26-May-2014' from dual union all
    select '25-Aug-2014' from dual union all
    select '25-Dec-2014' from dual union all
    select '26-Dec-2014' from dual) HOLIDAYS
    

    Hello

    the link is on MOSC, not OTN... Here's a copy:

    This function calculates the number of days between two dates, ignoring weekends and holidays (if requested and if the holidays are stored in a table)

    I give an example of table 'public_holiday' with sample data, but users must ensure that their table contains the relevant data (all holidays within the maximum range of use of the service)

    CREATE TABLE public_holiday (calendar_day, DATE, text VARCHAR2 (30));

    FUNCTION to CREATE or REPLACE nb_days (p_date_from IN DATE

    p_date_to DATE by DEFAULT TRUNC (sysdate)

    , p_public_holidays in CHAR DEFAULT 'Y '.

    ) RETURN NUMBER

    DEFINE AUTHID

    AS

    /*********************************************************************/

    / * Author: Bruno Vroman * /.

    / * Created: 23-AUG-2012 * /.

    / * Last updated: 23-AUG-2012 * /.

    / * Object: to calculate the number of days between 2 dates, to the exclusion of * /.

    / * Saturday and Sunday, but also "holidays" If the * /.

    / * argument 'p_public_holidays' = 'Y ' * /.

    / * Support: p_date_from<= p_date_to                             ="">

    / * component ' hour min dry "ignored (just counting days) * /.

    /* First step:                                                       */

    / * the calendar days between 2 days * /.

    / Remove 2 days for each "week" and 0 or 1 extra day * /.

    / * function to a condition "complex" mix day of first week * /.

    / * and the number of days when full remaining weeks are removed * /.

    / * (set up once for all, for example if there is 3 days and the * /)

    (/ * first day is a Thursday, there is 1 "Sat/Sun" to subtract) * /.

    / * Second step: If 'p_public_holidays' = 'Y': other * /.

    / * days, do not count holidays.                         */

    / Holiday everyday are defined in a table "public_holiday" * /.

    / * Note: there may be holidays defined on Saturday/Sunday.       */

    /*********************************************************************/

    l_result NUMBER;

    l_from DATE;

    l_to DATE;

    l_case tank (4);

    BEGIN

    l_from: = TRUNC (p_date_from);

    l_to: = TRUNC (p_date_to);

    l_case: = TO_CHAR (l_from, 'Dy', 'NLS_DATE_LANGUAGE = English').

    To_char (MOD (l_to - l_from + 1, 7));

    l_result: = l_to - l_from + 1

    -TRUNC ((l_to-l_from + 1) / 7) * 2

    -CASE

    WHEN l_case IN ('Mon6', 'Tue5', 'Wed4', 'Thu3', 'Fri2'

    , "Sat1", "Sun1", "Sun2', 'Sun3", "Sun4".

    , "Sun5', 'Sun6.

    )

    THEN 1

    WHEN l_case IN ('Tue6', 'Wed5', 'Wed6', 'Thu4', "Thu5"

    , 'Thu6', 'Fri3', 'Fri4', 'Fri5', 'Fri6 '.

    , "Sat2", "Sat3', 'Sat4', 'Sat5", "Sat6.

    )

    THEN 2

    0 OTHERWISE

    END

    ;

    IF SUPERIOR (p_public_holidays) = "Y".

    THEN

    SELECT l_result - COUNT (*)

    IN l_result

    OF public_holiday p

    WHERE p.calendar_day > = l_from

    AND p.calendar_day<=>

    AND SUBSTR (TO_CHAR (p.calendar_day

    , "Dy".

    'NLS_DATE_LANGUAGE = English'

    )

    , 1, 1 ) != 'S'

    ;

    END IF;

    RETURN l_result;

    EXCEPTION

    WHILE OTHERS

    THEN

    DBMS_OUTPUT. Put_line (' CTF nb_days (' |))

    To_char (p_date_from, "MON-DD-YYYY"). ', ' ||

    To_char (p_date_to, "MON-DD-YYYY"). ', ' ||

    p_public_holidays | ' ) : ' || SQLERRM

    );

    LIFT;

    END nb_days;

    /

    REM

    REM example:

    REM A) fill out the 'public_holidays '.

    REM

    TRUNCATE TABLE public_holiday;

    INSERT INTO public_holiday VALUES (DATE ' 2012-01-01', ' new year (a Sunday)');

    INSERT INTO public_holiday VALUES (DATE '' 2012-01-03, "for example");

    REM (insert other days...)

    COMMIT;

    Call the function for some pairs of dates of REM B)

    REM nb1: remove only Sat/Sun

    REM nb2: also remove holidays

    REM

    ALTER SESSION SET nls_date_format ='Dy DD-MON-YY';

    WITH some_dates AS

    (SELECT DATE ' 2011-12-29'd dual FROM

    UNION ALL SELECT DATE ' 2012-01-08' FROM dual

    UNION ALL SELECT DATE ' 2012-01-10' FROM dual

    )

    SELECT d1.d 'FROM '.

    , d2.d ' to THE '.

    , nb_days (d1.d, d2.d, ' don't) nb1

    , nb_days (d1.d, d2.d, 'Y') nb2

    OF some_dates d1

    some_dates d2

    WHERE d1.d<=>

    ORDER BY nb1, nb2, d1.d

    ;

    GO TO NB1 NB2

    ------------- ------------- ---- ----

    Monday, January 8, 12 Monday, January 8, 12 0 0

    Friday, December 29, 11 Friday, December 29, 11 1 1

    Wednesday, January 10, 12 Wednesday, January 10, 12 1 1

    Monday, January 8, 12 Wednesday, January 10, 12 2 2

    Friday, December 29, 11 Monday, January 8, 12 7 6

    Friday, December 29, 11 Wednesday, January 10, 12 9 8

    Hope that this could be useful, but note that this code has not been completely tested, so check and test before you trust it (in the case of any questions, please post a comment)

    Bruno Vroman.

    Best regards

    Bruno

  • 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 the difference in days between two Dates

    Hello

    I'm trying to understand how to calculate the difference in days between two dates using JavaScript in LiveCycle. (Minimum = JavaScript knowledge)

    Where 'Start_Date' and 'Current_Date' are the names of the two dates in the palette of the hierarchy. (the two Date/time field)

    * Current date is using the object > value > execution property > current Date/time

    I need a text or number field showing the difference in days. (Difference_in_Days)

    I noticed the following code is pretty standard among other responses:

    var

    Start_date = new Date (Start_Date);

    var

    Current_Date = new Date (Current_Date);

    var

    nAgeMilliseconds = Current_Date.getTime) - Start_date.getTime ();

    var

    nMilliSecondsPerYear = 365 * 24 * 60 * 60 * 1000 ;

    I know there is lack of code and code above are may not be not correct.

    Please notify.

    OK, that's because of the way that javascript and works of the calculate event.  The field will be filled with whatever the script resolves at the end of execution. Technically, your script does not have a value because the last thing you do is an assignment to a variable.  Change the last line as follows:

    Math.ABS ((firstDate.getTime)

    ((- secondDate.getTime (()) / (oneDay));

    (eliminate the variable assignment) and get rid of the app.alert.  Your script will "return" (have) regardless of the value of calculation from the East and which will be stored in the field.

  • to calculate the number of days between 2 dates

    Hi all


    I need to calculate the number of days between 2 dates.
    Y at - it no oracle built on that basis.



    Thanks in advance
    Kind regards

    Nick

    user646786 wrote:
    Hello

    Thanks a lot its really useful, but I must make a correction, I just want weekdays rather working days

    As already said, there are many examples on the forum of the calculation of the working days or the days of the week or whatever you want between certain dates of restrictions. You will need to have a go at adapting what has already been given before and then when you get stuck, come here and your postcode, and someone will take a look for you.

  • calculate the number of days excluding non-working days

    11.2.0.4

    theres a fairly common request over the years to get the diff between 2 dates, excluding weekends, theres many ways to to do, however, I would like to go a step further and exclude everything not professional

    day.

    We have a company function that calculates whether a date is a holiday for our Organization.  We can pass a date and we have a Y or N back.     In the example below, the l' appel call function shows there for Saturday to show how we can identify the non-working day.

    Can anyone think of a way that we could use to get a sum of N s between 2 date fields in a line using this function?   IM thinking if we get the right formula/function to create a virtual column with calculating pre built as it can start to get expensive if she had to loop through every possible day between 2 dates to see it is a business day, all by a count.

    create the table t1_count

    (identification number,

    date of TS1,

    date of TS2)

    insert into t1_Count

    values (1, sysdate, sysdate - 7);

    insert into t1_Count

    values (2, sysdate, sysdate - 4);    -Saturday

    commit;

    SELECT id, ts1 ts2, .isholiday (ts1), isholiday (ts2) of t1_count;

    106/03/2015-14:30:5127/05/2015 14:30:51NN
    106/03/2015-14:32:2930/05/2015 14:32:29NTHERE

    That fold to my brain...

    ABS (trunc (sysdate - 40) + level - 1 - trunc (sysdate)) that's equivalent to the abs (level - 41)...

    Why not just level<=>

  • Calculate the number of days off weekends


    Hi all

    I have a requirement where I have to calculate the difference between two dates, excluding weekends and holidays. Is there a way I can do it in OBIEE analysis.

    Any help would be appreciated.

    Thanks in advance!

    Check it for weekends cool - bi.com

    For the holidays, you will need to customize you the size of the day

    check if help

  • Calculate the number of days between two dates

    Hello

    Can someone help please change my formcalc script to calculate the number of working days between two date fields.  My script currently calculates the total number of days between two dates, including the weekends which must be excluded from the total.

    If

    (HasValue (Start_Date1) & HasValue (End_Date1)) then

    $

    = Date2Num (End_Date1, "YYYY-MM-DD" "en_IE") - Date2Num (Start_Date1, "YYYY-MM-DD" "en_IE") + 1

    on the other

    ""

    endif

    Any help will be most appreciated.

    Thank you.

    Check...

    (1) you said that you put the script on the event «days1» calculate My sample imitates the variable names used in the original message, "Start_Date1" and "End_Date1". If the names of variables for the start and end dates are different, you will need to modify the script to account for these names.

    (2) the Date2Num functions in the calculation of the "totalDays" use the date format "YYYY-MM-DD". If your date habits differ from "YYYY-MM-DD" FormCalc will complain.

    Steve

  • Dynamically calculate the number of days between two dates and amounts of split

    Hello

    I have searched for a solution for this, but had no success.
    I need to show the amounts broken down by days.

    I have a table that has an amount column and start and end dates.

    I need to write a query so that the amounts will be broken evenly based on the number of days between the start date and end date.

    For example, for this line.
    insert into my_test values (' 1, '' 3-mar-2010, ' 7 - mar - 2010 ", 1000);

    the query returns this (split $1,000 over 5 days)


    ID Date amount
    1 ' 3-mar-2010' 200,00
    1 ' 4-mar-2010' 200,00
    1 ' 5-mar-2010' 200,00
    1 ' 6-mar-2010' 200,00
    1 ' 7-mar-2010' 200,00



    create table my_test)
    ID number (10),
    start_date date,
    End_date date,
    amount number (10.2)
    );


    Select * from my_test

    insert into my_test values (' 1, '' 3-mar-2010, ' 7 - mar - 2010 ", 1000);
    insert into my_test values (2, 10-mar-2010 ", 19-mar-2010", 2000);
    insert into my_test values (3, 20-mar-2010 ',' 21-mar-2010, 5000);



    Thanks in advance.

    Hello

    One way is to join a Meter of Table , a table, or (more often) a set of results includes a line for eery number 1, 2, 3,... until the maximum number of times you need to divide a line.
    For example:

    WITH     cntr     AS
    (
         SELECT     LEVEL - 1     AS n
         FROM     (  SELECT  MAX (end_date - start_date)     AS max_day_cnt
                 FROM        my_test
              )
         CONNECT BY     LEVEL <= 1 + max_day_cnt
    )
    SELECT       t.id
    ,       t.start_date + c.n                    AS dt
    ,       t.amount / (t.end_date + 1 - t.start_date)     AS amt
    FROM       my_test      t
    JOIN       cntr            c     ON     c.n <= t.end_date - t.start_date
    ORDER BY  id
    ,            dt
    ;
    

    This assumes that all dates have the same number of hours, minutes, and seconds, as is the case in your sample data.
    If this isn't the case, then use TRUNC (start_date) and TRUNC (end_date) instead of start_date and end_date or post some sample data and results if some lines do not represent a whole number of days.

  • How to calculate the number of days between dates

    How can I determine the number of days between 2 dates? Say today and 10/07/46

    Thanks Bob

    You could do it like this:

    Photoperiod var = 1000 * 60 * 60 24; number of ms in a day

    var today: Date = new Date();

    var every time that: Date = new Date (1946,6,10);

    var diff = Math.floor((today.getTime()-whenever.getTime())/dayLength);

    trace (diff)

  • Calculate the last business day

    Hello

    I use Oracle Database 11.2.1 and wants to return to the last day of work (JJ/MM/AAAA).

    Working days Monday to Friday delivery

    for example on Sunday, 18 June 2000, the returned value would be Thursday, June 15, 2000

    sliderrules wrote:
    I wanted to say the days of the week

    for example, Monday, May 13, 2013 would return 10/05/2013
    Tuesday, May 14, 2013 would return 13/05/2013 etc.

    What the earlier query?

    SQL> with t as
      2      (
      3      select to_date('13/05/2013 ','dd/mm/yyyy') dt
      4      from dual
      5      union all
      6      select to_date('14/05/2013 ','dd/mm/yyyy') dt
      7      from dual
      8      )
      9      select dt,dt -
     10             case to_char(dt,'fmday','nls_language=english')
     11                         when 'sunday' then 2
     12                 when 'monday' then 3
     13                else 1
     14            end last_w_day
     15     from t;
    
    DT        LAST_W_DA
    --------- ---------
    13-MAY-13 10-MAY-13
    14-MAY-13 13-MAY-13
    
  • calculate the total of days

    Hello world

    I have 2 items in date:

    p9_begin and p9_end

    I want to show every Sunday between these two days, and the total number of Sundays.
    I also want to show the total number of days less on Sundays.

    I can't think of a solution for this. I tried to loop, but it doesn't seem to work properly.
    Does anyone have a suggestion?

    Kind regards
    Diana

    Hi Diana,

    You could do something like:

    WITH X AS (SELECT TO_DATE(:DATE1,'DD/MM/YYYY') + LEVEL - 1 THE_DATE FROM DUAL CONNECT BY TO_DATE(:DATE1,'DD/MM/YYYY') + LEVEL - 1 < TO_DATE(:DATE2,'DD/MM/YYYY'))
    SELECT (SELECT COUNT(*) FROM X WHERE TO_CHAR(THE_DATE, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH') = 'SUN') SUNDAYS,
    (SELECT COUNT(*) FROM X WHERE TO_CHAR(THE_DATE, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH') <> 'SUN') OTHERDAYS
    FROM DUAL
    

    which would give you your Sunday/non-dimanche. pus

    WITH X AS (SELECT TO_DATE(:DATE1,'DD/MM/YYYY') + LEVEL - 1 THE_DATE FROM DUAL CONNECT BY TO_DATE(:DATE1,'DD/MM/YYYY') + LEVEL - 1 < TO_DATE(:DATE2,'DD/MM/YYYY'))
    SELECT THE_DATE FROM X
    

    I will give you all the dates.

    : DATE1 is some element contains your 'count' and: DATE2 is your "to this day".

    Andy

  • 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 )
    
  • Function to calculate the days of work

    Hi all

    I accidentally develop an application in which I had to follow the thread below and it works perfectly for the weekend (Saturday and Sunday)

    PL/SQL function to calculate the non-working days

    Now, my specific question is: how to implement the same function , but weekends (Fri & sat).

    I tried to recognize the logic behind the calendar to change the days of the weekend, but I suspect.

    I need your recommendation around this function specifically.

    !-[CodeBlockStart:3cad70b5 - 81 a 0-4f6b-909 a-cacb29e25953]--> BOX WHEN IN l_case (-"Mon6", "Tue5", "Wed4", "Thu3", "Fri2" - exclude Saturday & Sunday, workday begins from Monday 'Sun6', 'Mon5', 'Tue4', 'Wed3', 'Thu2' - remove begins day 2 business days (Fri & sat) on Sunday and maintaining the order of the sequences,-"Sat1", "Sun1", "Sun2', 'Sun3', 'Sun4' - Include weekend can be for the rest of the week) , "Sat1", "Sat2", 'Fri1', "Sat3", "Sat4" - includes my week ends replace (with FRI Sat) & (Sun to SAT) & law enforcement-sequence, "Sun5', 'Sun6',"Sat5","Sat6"- replace (Sun with Sam).                                                                   ) 1 THEN WHEN IN l_case (-'Tue6', 'Wed5', 'Wed6', 'Thu4', "Thu5" - Old (Saturday and Sunday) end over the next week - I guess - sequence of days - since the week days sequence Changed (number 1 or 1 step backward) when numbers also changed accordingly "Tue5", "Wed4", "Wed5", "Thu3", "Thu4" - ok-, 'Thu6', 'Fri3', "Fri4", "Fri5", "Fri6", "Thu5", "Sun1", "Sun2", 'Sun3', 'Sun4' - contiue to Thu sequence number & then replace my current (Friday) holiday with start of work dat (Sun) "Fri1") (, 'Fri2', 'Fri3', 'Fri4', "Fri5") THEN 2 0 OTHERWISE END;

    Thanks in advance.

    Amatu Allah

    with

    calendar as

    (select dat_val,

    cases where to_char(dat_val,'mm-dd') in (12-25', 12-26', ' 01-01')-in fact select the host table to_char(holiday_date,'mm-dd')

    then "vacation."

    When to_char (dat_val, 'Dy') in ('Friday', 'Saturday')

    then 'weekend '.

    else 'work '.

    end dat_type

    sum (case when to_char(dat_val,'mm-dd') in (12-25', 12-26', ' 01-01'))

    then 0

    When to_char (dat_val, 'Dy') in ('Friday', 'Saturday')

    then 0

    1 other

    end

    ) on working_count (dat_val control)

    from (select date "' 2015-12-01 + level - 1 dat_val)

    of the double

    connect by level<=>

    )

    )

    Select dat_val,

    dat_type,

    working_count

    calendar

    where dat_val between to_date(:lo_date,'yyyymmdd') and to_date(:hi_date,'yyyymmdd')

    and dat_type! = work «»

    DAT_VAL DAT_TYPE WORKING_COUNT
    11/12/2015 end of week 8
    12/12/2015 end of week 8
    18/12/2015 end of week 13
    19/12/2015 end of week 13
    25/12/2015 holiday 18
    26/12/2015 holiday 18
    01/01/2016 holiday 23
    02/01/2016 end of week 23
    08/01/2016 end of week 28
    09/01/2016 end of week 28

    Select to_date(:lo_date,'yyyymmdd') lo_date,

    to_date(:hi_date,'yyyymmdd') hi_date,

    dat_val,

    dat_type,

    working_count,

    Lead (working_count) more (order of dat_val) - working_count + 1 working_days,

    to_date(:hi_date,'yyyymmdd') - to_date(:lo_date,'yyyymmdd') - lead (working_count) (order dat_val) + working_count non_working_days

    calendar

    where dat_val in (to_date (:hi_date,'yyyymmdd'),to_date(:lo_date,'yyyymmdd'))

    LO_DATE HI_DATE DAT_VAL DAT_TYPE WORKING_COUNT WORKING_DAYS NON_WORKING_DAYS
    10/12/2015 10/01/2016 10/12/2015 work 8 22 10
    10/12/2015 10/01/2016 10/01/2016 work 29 - -

    Concerning

    Etbin

Maybe you are looking for