How to calculate an interval between two dates?

Hi all

I have two dates, and I need to know if the interval between the two is more than 30 days or not. I can't understand how to calculate this interval.
Could someone help me?
Thank you very much.

See the following forumpost:

Re: Calculation of difference in date in BPEL

Kind regards

Melvin

Tags: Fusion Middleware

Similar Questions

  • How to calculate the hours between two dates by the numbers

    If I update 09:00 start time 17:00 end time of shift in C3 and B3, how to use a D3 formula to calculate the number of hours between the two?  Then I can just copy down the lines for nth years...

    It is a spreadsheet of the part-time staff payroll.

    I'm sure that a lot of people out there have done that.

    Help, please.

    Thank you.

    Eddie

    What program of worksheet that you are using? Since you have a newer iMac running El Capitan, I can safely assume that you use NOT AppleWorks, which is a Power PC application that can run on any OS newer than the snow leopard, OS X 10.6.8.

    If you use numbers, try to repost your question in numbers for Mac forum. If you use Microsoft Excel, try posting in the Microsoft forums. LibreOffice also has community support.

  • Calculate business hours between two dates in a cursor

    Hello, its me again (?).

    Yesterday, I got a solution to a problem here where I need to calculate the hours between two dates, excluding Sat/Sun and from 09:00 to 18:00. I'm now putting this login in a PL/SQL block, so I can calculate it for each record in a slider, all by looping.
    with t (start_date
           ,end_date
           )
    as (select  to_date('22-oct-2012 09:00:00','dd-mon-yyyy hh24:mi:ss') start_dt,
                           to_date('23-oct-2012 09:00:00','dd-mon-yyyy hh24:mi:ss') end_dt
        from dual
       )
    , hrs (dt) as
      (select start_date
       from   t
       union all
       select dt +1/24/60
       from   hrs
       where  hrs.dt < (select end_date-1/24/60 from t)
      )
    select count(*)/60
    from hrs
    where to_char(dt,'dy') not in ('sat','sun')
    and  to_number(to_char(dt,'hh24')) not between 18 and 23
    and  to_number(to_char(dt,'hh24')) not between 0 and 8
    /
    The logic above, I'm up here:
    FOR c_record IN c_1 LOOP
    //For each record, check if the two dates meet the criteria and then raise the counters accordingly
    select  to_date(c_record.REPORTADA,'dd-mon-yyyy hh24:mi:ss') INTO vFch1 FROM DUAL;
    SELECT  to_date(c_record.INICIOREAL,'dd-mon-yyyy hh24:mi:ss') INTO vFch2 FROM DUAL;
    
    IF ((vHoras > 2) AND c_record.PRIORIDAD=3) THEN
      vContOk :=vContOk + 0;
      vContBad := vContBad+1;
      vContOt   := vContOt+1;
    ELSE 
      vContOk :=vContOk +1;
      vContBad := vContBad+0;
      vContOt   := vContOt+1;
    END
        IF;
    
    IF ((vHoras > 4) AND c_record.PRIORIDAD=2) THEN
      vContOk :=vContOk + 0;
      vContBad := vContBad+1;
      vContOt   := vContOt+1;
    ELSE
      vContOk :=vContOk +1;
      vContBad := vContBad+0;
      vContOt   := vContOt+1;
    END IF;
    
    IF ((vHoras > 16) AND c_record.PRIORIDAD=1) THEN
      vContOk :=vContOk + 0;
      vContBad := vContBad+1;
      vContOt   := vContOt+1;
    ELSE
      vContOk :=vContOk +1;
      vContBad := vContBad+0;
      vContOt   := vContOt+1;
    END IF;
    
    END LOOP;
    I really don't like if the performance is horrible because it will run once a month and should spend only 40-100 records.
    However, I can't find a way to use this connection even in this case

    Could you help me?
    Thank you!

    Greetings,
    NACEUR

    N wrote:
    I need to calculate the number of minutes between two dates, only count the hours from 9 to 18hs.

    CREATE OR REPLACE
      FUNCTION get_bus_minutes_between(
                                       p_start_date DATE,
                                       p_end_date DATE
                                      )
        RETURN NUMBER
        IS
            v_return NUMBER;
        BEGIN
            with t as (
                       select  case level
                                 when 1 then greatest(p_start_date,trunc(p_start_date) + 9 / 24)
                                 else trunc(p_start_date) + level - 15 / 24
                               end start_dt,
                               case connect_by_isleaf
                                 when 1 then least(p_end_date,trunc(p_end_date) + 18 / 24)
                                 else trunc(p_start_date) + level - 8 / 24
                               end end_dt
                         from  dual
                         connect by level <= trunc(p_end_date) - trunc(p_start_date) + 1
                      )
            select  sum(greatest(end_dt - start_dt,0)) * 24 * 60 work_minutes
              into  v_return
              from  t
              where trunc(start_dt) - trunc(start_dt,'iw') < 5; -- exclude weekends
            RETURN v_return;
    END;
    /
    

    For example:

    SQL> select get_bus_minutes_between(
      2                                 to_date('20-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss'),
      3                                 to_date('22-oct-2012 13:21:00','dd-mon-yyyy hh24:mi:ss')
      4                                ) work_minutes
      5    from dual
      6  /
    
    WORK_MINUTES
    ------------
             261
    
    SQL> 
    

    SY.

  • Calculate the hours between two dates

    Hello

    I have a requirement to count the hours with 2 given timestamps, something like:
    SQL> select ((to_date('22-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss') - to_date('20-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss'))*24) B from dual ;
    
             B
    ----------
            48
    However, I wish it would be that simple. I just need to count the hours between two timestamps for the hours of work for example, 08:00 - 17:00, MONDAY to Friday (excluding weekends).
    So lets say I have to count the hours between two dates above the result should be 18 hours not 48 (4 hours on 20/oct, 9 hours on 21/oct to 5 hours 22/oct).
    How can I achieve this? Any idea will be useful.

    Thank you

    My query generates a list of all the hours between the start and end time, filters on the hours that are outside of the hours of work and then account for the remaining lines. Change that to partial hours must just be a case of replace the two occurrences of 1/24 with 24/01/60, then - as say you - Division COUNT (*) by 60.

    There may be performance issues using techniques of generation of line like this, if you put this in a query involving the joining of several lines of other tables (for example where the dates of beginning and end are derived from several employees?) or in several days. If you don't find it then count the number of whole days (taking weekends into account) between dates and work on the partial days after that it could be better. This would probably involve a lot of statements of case (which I don't have time to test it now).

    Ben

  • How to find the difference between two dates in the presentation layer

    Hi gurus,

    Hello to everyone. Today, I came with the new requirement.


    I need to know the difference between a date and the current date in the formula column application presentation layer.by.



    Thank you and best regards,
    Prates

    Hi Navin,

    TIMESTAMPDIFF function first determines the timestamp component that corresponds to the specified interval setting. For example, SQL_TSI_DAY corresponds to the day component and SQL_TSI_MONTH corresponds to the component "month".

    If you want to display the difference between two dates in days using SQL_TSI_DAY, unlike butterflies SQL_TSI_MONTH and so on...

    hope you understand...

    Award points and to close the debate, if your question is answered.

    See you soon,.
    Aravind

  • Length of the different interval between two dates in SQL/PLSQL

    Dear gurus, here are three questions to ask:
    1. Why is the result queries are different?
    2 - is a way to measure the length of the interval in seconds (L) between two dates?
    2. why the different result is generated in SQL and PL/SQL only to subtract dates from the 28th day of the month?

    declare
    number of l_offset;
    Start
    l_offset: = (to_date('09-nov-2009') - to_date ('28.10.2009 10:40:03 ', ' dd.mm.yyyy hh24:mi:ss')) * 86400;))
    dbms_output.put_line (l_offset);
    l_offset: = (to_date('09-nov-2009') - to_date ('27.10.2009 10:40:03 ', ' dd.mm.yyyy hh24:mi:ss')) * 86400;))
    dbms_output.put_line (l_offset);
    end;
    998396.9999999999999999999999999999999997
    1084797


    Select (to_date('09-nov-2009') - to_date ('28.10.2009 10:40:03 ', ' dd.mm.yyyy hh24:mi:ss')) * double 86400))
    Union of all the
    Select (to_date('09-nov-2009') - to_date ('27.10.2009 10:40:03 ', ' dd.mm.yyyy hh24:mi:ss')) * double 86400))
    (TO_DATE('09-NOV-2009')-TO_DAT
    998397
    1084797


    Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
    PL/SQL Release 9.2.0.7.0 - Production
    CORE 9.2.0.7.0 Production
    AMT for Linux: release 9.2.0.7.0 - Production
    NLSRTL Version 9.2.0.7.0 - Production

    Hello

    Sorry, I'm still not sure you understand the question.

    You wonder why the rounding error is apparent to 6 digits to the left of the decimal separator in numbers, but not in number 7 digits to the left of the decomal? The answer is itself a rounding error.
    When Oracle is the arithmetic mean of the dates, the result is a fraction that cannot be stored in a binary number, such as preciesly
    998396.9999999999999999999999999999999996857... it it rounds to the nearest value it can store, such as
    998396.9999999999999999999999999999999997. in other words, it can store 40 digits. In this case, 6 figures to the left of the decimal separator and 34 of the figures to the right. The number is rounded to the nearest multiple of 10 ^-34 ^
    What happens if we add 86400 this number?

    
     998396.9999999999999999999999999999999997
    + 86400.0000000000000000000000000000000000
    ------------------------------------------
    1084796.9999999999999999999999999999999997
    

    Now we need 7 digits before the comma, then round the number to the nearest multiple of 10 ^-33 ^, which is
    1084797.000000000000000000000000000000000

  • How to calculate the difference between a Date column and the Date yesterday in the analysis (in the formula in the column)

    . For example, I need to calculate the difference between a date column, 'Table_Name '. "' Column_Name ' and (Current_Date-1). I tried different ways to do this. But nothing seems to work.

    Try the below formula.

    Replace "Time". "" Date "with your column.

    TIMESTAMPDIFF (SQL_TSI_DAY, "Time". "Date", TIMESTAMPADD (SQL_TSI_DAY-1, CURRENT_DATE))

    Thank you!

  • How do the time difference between two dates?

    Hi all

    I use this query to get the time difference between two dates.

    Select to_timestamp ('2012-10-03 12:00 ',' YYYY-MM-DD hh)-to_timestamp ('2012-10-03 11:00 ',' YYYY-MM-DD hh) as double diff;

    but do not get the correct result.

    Thank you

    Left KEY... Left Padding of tanks.

  • How to calculate the difference between 2 dates, but with interruptions and stops between

    Hello

    How can I calculate the difference in minutes between 2 dates but taking into account the existence of a table in the Appendix, so if between start_date and end_date arguments, there is no 'work time' then this part of the time will not be included in the total difference.

    Records of the time table example:

    Time_configuration start_hour end_day end_hour
    219:00307:00
    319:00407:00

    so for example first record said that on Monday you start at 19:00 and leave the next day at 7:00 and then save the same sort of thing.

    There is an event that I want to track how many minutes lasted. for example, this event began the day 2 at 19:00 and ended the day 3 at 21:00

    Theoretically, this event really lasted: 840 minutes. This 840 minutes are within the limits of the annex.

    Thanks in advance.

    The storage of the dates not as data type DATE in most cases is bad design. In addition, how do you know what day of the date is 2 at 19:00? East - Monday 2 November 2015 or Monday, March 7, 2016? It is the same for the event. In any case, assuming that both calendar and events don't extend over several weeks:

    According to schedule)
    Select time_configuration 2, 19:00 ' start_hour, end_day 3,' 07:00 ' end_hour of all the double union
    Select 3, 19:00 ', 4,' 07:00 ' double
    ),
    event like)
    Select event_id 1, time_configuration 2, 19:00 ' start_hour, end_day 3: 21:00 ' end_hour of the double
    )
    Select e.event_id,
    Sum)
    less (e.end_day + to_date (e.end_hour, 'HH24'), s.end_day + to_date (s.end_hour, 'hh24:mi')).
    greater (e.start_day + to_date (e.start_hour, 'HH24'), s.start_day + to_date (s.start_hour,'hh24:mi'))))
    ) * 24 * 60 minutes
    Appendix s,
    e event
    where e.start_day + to_date(e.start_hour,'hh24:mi')< s.end_day="" +="">
    and e.end_day + to_date(e.end_hour,'hh24:mi') > s.start_day + to_date(s.start_hour,'hh24:mi')
    E.event_id group
    /

    EVENT_ID MINUTES
    ---------- ----------
    1 840

    SQL >

    SY.

  • How to tell the difference between two dates

    Hello:

    I have a question on how to get the difference in quantities for two dates in the replies and dashboard.

    This is the scenario. I have two guests date and three columns. The first column must be the sum of the amounts for the first quick date. The second column should be the sum of the amounts for the second fast date. And the third column is the difference between the first two columns.

    Basically, I'm trying to do something similar to a function of sum of two lines but trying to get the difference between the two rows. Any help to solve this problem would be appreciated.

    Use the COLUMN FILTERS level...

    the first column with the first variable of date quick presentation of the filter

    Similarly, the second column in the second variable of quick overview of date filter

    Kind regards
    Rambeau

  • How to find the difference between two dates in time except Sunday

    Hi all

    I have a table, as shown below.
    SQL> select * from test;
    
    TR_ID                                              CREATE_TIME                                                                       CODE
    -------------------------------------------------- --------------------------------------------------------------------------- ----------
    S12341                                             05-JUN-12 12.20.52.403000 AM                                                      1003
    S12342                                             11-JUN-12 11.15.33.182000 AM                                                      1003
    S12342                                             07-JUN-12 12.00.36.573000 PM                                                      1002
    S12343                                             20-JUN-12 12.34.37.102000 AM                                                      1003
    S12343                                             15-JUN-12 11.34.27.141000 PM                                                      1002
    S12344                                             01-JUL-12 10.01.06.657000 PM                                                      1002
    S12344                                             06-JUL-12 12.01.04.188000 AM                                                      1003
    S12341                                             31-MAY-12 11.20.38.529000 PM                                                      1002
    I would like to know the difference between same tr_ids create_time, which should give out in hours except Sunday.

    For example:

    TR_ID: S12344
    1002_Create_time: July 1, 12 PM 10.01.06.657000 (i.e. Sunday)
    1003_Create_time: 12.01.04.188000 AM 6 July 12

    1002 create time is 22:00 Sunday.

    If the query must exclude only the hours of Sunday which is 10 p.m. to Monday 00 h which is 2 Hrs.

    I tried the sub query after doing a search on this forum but I am not getting the desired output.
    SELECT count(*) FROM (SELECT ROWNUM RNUM,tr_id,create_time CT_1002 FROM test c WHERE c.tr_id='S12344' and 
    ROWNUM <= (select (cast(a.create_time as date)-cast((select create_time from test b where a.tr_id=b.tr_id and code=1002) as date)) 
    from test a where a.code=1003 and a.tr_id=c.tr_id) + 1) d 
    WHERE to_char(cast((select create_time from test e where e.tr_id=d.tr_id and code=1002) as date) + RNUM - 1, 'DY') NOT IN('SUN');
    Need help to get the desired o/p

    Hello

    If I unederstand the problem correctly, that's what you want:

    WITH       got_extrema     AS
    (
         SELECT       tr_id
         ,       CAST (MIN (create_time) AS DATE)     AS start_date
         ,       CAST (MAX (create_time) AS DATE)     AS end_date
         FROM       test
         GROUP BY  tr_id
    )
    SELECT       tr_id
    ,       start_date, end_date          -- If wanted
    ,       24 * ( ( ( TRUNC (end_date,   'IW')          -- Count -1 day for every full week
                        - TRUNC (start_date, 'IW')
                 )
               / -7
                  )
                + LEAST ( end_date               -- If end_date is a Sunday
                            , TRUNC (end_date, 'IW') + 6     -- consider it 00:00:00 on Sunday
                     )
                - CASE
                          WHEN  start_date >= TRUNC (start_date, 'IW') + 6     -- If start_date is a Sunday
                   THEN  TRUNC (start_date, 'IW') + 6               -- consider it 00:00:00 Sunday
                   ELSE  start_date
                      END
                )     AS total_hours
    FROM      got_extrema
    ;
    

    I guess that you don't need to worry about fractions of a second. As you did in the code you have posted, I am to convert the TIMESTAMP to date values, because of DATE arithmetic and functions are so much better than what is available for timestamps.

    Basically, it's just to find the number of days between start_date and end_date and multiplying by 24, with these twists:
    (a) 1 day is deducted for each week between start_date and end_date
    (b) if End_date is a Sunday, none of the end_date himself hours are counted
    (c) If start_date is a Sunday, then all the start_date himself hours are counted. Why these hours should be counted? Because 1 day is already being deducted for the week which includes start_date, which contains only this Sunday.

    TRUNC (dt, 'IW') is the beginning of the ISO week containing dt; in other words, 00:00:00 the or before the dt last Monday. This is not the NLS parameters.

    Of course, I can't test without some sample data and the exact results you want from these data. You may need a little something more If start_date and end_date are both on the same Sunday.
    Whenever you have a problem, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) of all of the tables involved.
    Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
    Always tell what version of Oracle you are using.
    See the FAQ forum {message identifier: = 9360002}

  • How to calculate the difference between two times by the NUMBERS

    I'm so bothered by the fact that I can't understand that.

    Cell B2 - 08:00

    Cell C2 - 10:50

    (How can cell D2 - I get this cell to calculate the difference and say 02:50?)

    I know it's probably one of the most basic operations, but for the life of me I can't understand it. The cells B2 and C2 are formatted for a 24-hour clock. But if I tell the system to just subtract the two, I get "0,118. Everything I find on the forum search goes beyond what I need. Can someone help me?

    Thank you

    Hi sapirs,

    Departure and arrival of the cells are in Date and time with Date format: no and time: 24-hour clock.

    Formula in D2 (fill down)

    = C2−B2

    The results become a duration format, but under automatic (numbers automatically worth this format)

    If you wish, you can change the cells of lasting results.

    What Data Format have your result cells?

    Kind regards

    Ian.

  • Figure out how many years and days between two dates

    Nice day

    I've been dealing with the problem for a few days now so I thought that I could send it and see if someone can tell me what I'm doing wrong.

    / * Create a Date with a date object. */

    var d1 = getField "(RELEASE. DATE') .value;

    / * Create a date object containing the current date. */

    var d2 = getField("Text4").value;

    / * Number of years difference. */

    diff = (((d2.valueOf () - d1.valueOf (()) / 1000) / 60) / 60) / 24) / 365;

    Displays the field "Text3".

    getField("Text3").value = (diff); & #8232;
    < END >

    RELEASE. Value DATE is January 1, 2011, with a date format dd/mmm/yyyy

    Text4 value is March 1, 2011 with a date format dd/mmm/yyyy

    The release of Text3 gives me a 'NaN' result

    What I'm trying to do is calculated the number of years an employee has had with the company, and then display a balance of days that he had.

    Any thoughts would be greatly appreciated.

    repeated conversion from date string and number of days for the reuse of code
    function Date2Num (cFormat, cDate) {}
    Converts a date string formatted in days since the date of the time
    Kai var = util.scand (cFormat, cDate);
    Math.floor (oDate.getTime (return) / (1000 * 60 * 60 * 24));
    }

    / * Create a Date with a date object. */
    var d1 = (getField("Enrol_Day").value + "/" + getField("EnrolMonth").value + "/" + getField("EnrolYear").value);
    Converts a date in the date object string
    oD1 var = util.scand ("dd/mmm/yyyy", d1);
    get the current date of the field
    var d2 = (getField ("TD. RelDay") .value + ' / ' + getField ("TD. RelMonth") .value + ' / ' + getField ("TD. (RelYear') .value);

    calculate the difference in days
    diff var = Date2Num ("dd/mmm/yyyy", d2) - Date2Num ("dd/mmm/yyyy", d1);
    increment the value if the end date should be included in the calculation
    diff ++;
    convert days to truncate all years - to the next intiger lowest
    var carnavalSVP = Math.floor(diff / 365.25);
    get the current year interval - rest of diff days divided by 365.25 days
    var nDays = Math.floor (diff % 365.25);

    display the entered values
    CMSG var = ' end date: "+ d2 +" \t Compute days: ' "+ Date2Num (" dd/mmm/yyyy", d2);
    CMSG += "\nStart date:" + d1 + "\t Compute days: '" + Date2Num ("dd/mmm/yyyy", d1);
    Total difference in days
    CMSG += "\nTotal elapsed days:"+ diff;»
    result in years and days
    CMSG += "\nYears:" + carnavalSVP + "and" + nDays + 'days'; "."
    App.Alert (GSMC, 1, 0, "results");
    //

  • How to calculate the difference between two numbers in text fields

    Hello, I am fairly new to this, and I am certain that I will be bothered by the simple answer is

    I do a simple calculation... total of total assets - liabilities = net worth

    I have my total assets and my total work of the liability, but is not a subtraction option in the properties of a text field for the Net of a field value.

    I don't know... not any script Java can any who help out me?

    Thank you

    Judy

    You can use the option of simplified field notation, but first your input fields names must be changed so that they do not contain spaces or punctuation. For example:

    TotalAssets - TotalLiabilities

    If you want to use JavaScript, what will be needed if you ever in more complicated calculations, you can use something like the following as the custom fields (net value) calculation script:

    (function () {}

    Get the values of the field as numbers

    var v1 = + getField("total_assets").value;

    var v2 = + getField("total_liabilities").value;

    calculate the value of this field

    Event.Value = v1 - v2;

    })();

    There are no restrictions on domain names when using JavaScript.

  • Calculate business hours between 2 dates with negative numbers

    Hi all

    I use a function to calculate the difference between 2 dates schedules. The function was taken and adapted from this thread:

    Calculate business hours between two dates in a cursor

    CREATE OR REPLACE
      FUNCTION get_bus_minutes_between(
                                       p_start_date DATE,
                                       p_end_date DATE
                                      )
        RETURN NUMBER
        IS
            v_return NUMBER;
        BEGIN
            with t as (
                       select  case level
                                 when 1 then greatest(p_start_date,trunc(p_start_date) + 9 / 24)
                                 else trunc(p_start_date) + level - 15 / 24
                               end start_dt,
                               case connect_by_isleaf
                                 when 1 then least(p_end_date,trunc(p_end_date) + 20 / 24)
                                 else trunc(p_start_date) + level - 4 / 24
                               end end_dt
                         from  dual
                         connect by level <= trunc(p_end_date) - trunc(p_start_date) + 1
                      )
            select  sum(greatest(end_dt - start_dt,0)) * 24 * 60 work_minutes
              into  v_return
              from  t
              where trunc(start_dt) - trunc(start_dt,'iw') < 5; -- exclude weekends
            RETURN v_return;
        END;
        /

    I am running into an issue that when the p_end_date is before the p_start_date value the function returns the full time between the dates without regard for business hours. if the end_date is before the start date I get the expected result i.e. difference between the dates in business hours.

    Using example dates of start 19th October 2012 13:00:00 and end 22nd october 2012 13:21:00 the business minutes are 681. However if i reverse the dates I get -4341.


    Correct labour code is the following, I've annotated so that he could help someone else looking for a solution like this:

    CREATE OR REPLACE
      FUNCTION get_bus_minutes_between(
                                       p_start_date DATE,  --these are the 2 dates passed into the function
                                       p_end_date DATE     --these are the 2 dates passed into the function
    )
    RETURN NUMBER
    IS
    v_return NUMBER;

            l_start  DATE;

            l_end    DATE;

            l_factor NUMBER;
        BEGIN

            IF p_start_date <= p_end_date THEN            --this IF section checks which of the 2 dates is the greatest

               l_start  := p_start_date;                  -- and then assigns the earliest date to p_start_date

               l_end    := p_end_date;

               l_factor := 1;

            ELSE   -- swap the dates around, and multiply the result by -1

               l_start  := p_end_date;

               l_end    := p_start_date;

               l_factor := -1;

            END IF;

            with t as (
                       select  case level
                                 when 1 then greatest(l_start,trunc(l_start) + 9 / 24)  -- this sets the start of working hours
                                 else trunc(l_start) + level - 15 / 24  --if the start time is adjusted this value must also be adjusted
                               end start_dt,
                               case connect_by_isleaf
                                 when 1 then least(l_end,trunc(l_end) + 20 / 24)  -- this sets the end of working hours
                                 else trunc(l_start) + level - 4 / 24  -- if the end time is adjusted this value must also be adjusted
                               end end_dt
                         from  dual
                         connect by level <= trunc(l_end) - trunc(l_start) + 1
                      )
            select  sum(end_dt - start_dt) * 24 * 60 work_minutes  -- this subtracts the 2 dates and then multiplies by hours and minutes
              into  v_return
              from  t
              where trunc(start_dt) - trunc(start_dt,'iw') < 5; -- this exclude weekends
            RETURN v_return * l_factor;  -- this gives the negative or positive results so you can see if it was completed before or after the required date.
        END;
        /

Maybe you are looking for