Check the hours between 2 datetime value

Hi all

How can - I to select lines, where between 2 hours, doesn't bother me what date they have.

date2 date1

(1) 20/04/2015 08:30 20/04/2015 09:30

(2) 21/04/2015 10:00 21/04/2015 11:00

I have a varchar(HH24:MI) i.e. myhours = 09:15

I have to get the first row

SELECT count (*) of myhours between TO_CHAR (date1, 'HH24') and TO_CHAR (date2, 'HH24');

In this case, I have to get 1 (exists), instead, if I myhours = 12:00 I get 0 (does not exist)

Thanks in advance

select count(*)
  from my_table
 where to_date('01-01-1900' || my_hour, 'dd-mm-yyyyhh24:mi') between to_date('01-01-1900' || TO_CHAR(date1, 'HH24:MI'), 'dd-mm-yyyyhh24:mi')
                                                                 and to_date('01-01-1900' || TO_CHAR(date2, 'HH24:MI'), 'dd-mm-yyyyhh24:mi');

Tags: Database

Similar Questions

  • 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

  • Count the hours between the times of the day

    Hello

    It is a timesheet, calculation of payment:

    I'm trying to find a way to calculate how many hours is between two specific times of the day.

    I enter a start time and an end time (in 2 different items), I calculate the number of hours that is. What I can understand.

    Then I need to know how many hours is between 16:00 and 22:00.

    The reason is that there is an additional extra payment for those hours.

    So: "payment on time' X ' total hours work in a day ' + 'bonus' X ' hours between 16 and 22" = "total wages for a day" "»

    Thank you

    Enter the full date and time in columns A and B (for example ' 12 Sep 2016 8:00 AM "or you like the what ever valid date time value):

    C2 = B2−A2

    D2 = C2−DURATION (0, 0, 24 × MAX (TIMEVALUE "(04:00 PM)") −TIMEVALUE (A2), 0)) −DURATION (0, 0, 24 × MAX (TIMEVALUE (B2) −TIMEVALUE (' 22:00 "" "), 0))

    Select cells C2 and D2, copy

    Select cells C2 at the end of column D, dough

    If you prefer the values in column D as decimal hours use the formula:

    dur2hours (D2)

    or replace the formula earlier as follows:

    D2 = dur2hours (C2−DURATION (0, 0, 24 × MAX (TEMPSVAL ("04:00 PM") −TIMEVALUE (A2), 0)) −DURATION (0, 0, 24 × MAX (TIMEVALUE (B2) −TIMEVALUE (' 22:00 "" "), 0)))

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

  • How to check the page dirty with default values existing in viewObject?

    Hi all

    I use JDeveloper 11.1.1.4.

    I have two pages in my application. I am browsing for page2 page1.

    Before opening page 2 I created new line page 2 notice of object using method 'Create Insert()' with some default values by using the ViewRowImpl class.

    My problem is that I have a button to return to Page 2. If I click the back button, then check the Application module is dirty or not.

    But it always shows AM is dirty due to I'm setting some default values in ViewRowImpl. If I avoid the default values in ViewRowImpl then AM dirty check works fine.

    My Question is how to check the AM (or) dirty Page with default values in the object view?

    My bean Codes:

    Links DCBindingContainer = (DCBindingContainer) BindingContext.getCurrent () .getCurrentBindingsEntry ();

    DataControl dc = bindings.findDataControl("AppModuleDataControl");

    ApplicationModuleImpl am = ((ApplicationModuleImpl) dc.getDataProvider ());

    If (am.getDBTransaction (.isDirty (()))

    {

    return "Page is dirty."

    }

    My Jspx Codes:

    < af:commandLink id = "cl6" text = '2 '.
    shortDesc = "Add Row in Page2"
    actionListener = "#{bindings." Action CreateInsert.execute}' = 'Edit' >

    Thank you

    David...

    see this

    http://www.techartifact.com/blogs/2013/11/how-to-check-ifdirty-is-modified-for-view-object.html

    http://www.jobinesh.com/2011/05/checking-for-dirty-data.html

  • Check the distance between the objects when the window is resized (was: Muse Help)

    If I build a new website havn't Muse widely used yet, and I encountered a problem.

    http://jart01.BusinessCatalyst.com/index.html it comes to my test site, as you can see at present still very basic. Now, I'm trying to understand how I can control the distance between objects when the window expands or contracts, there seems little of the larger window and the gap between objects. Does anyone know how to set limits to the distance between them?

    I also tried to create a divisor of 100% for the Nav menu and can't get there either. So if someone could put me on the right track this would be great.

    You must define the flow layout and do the 100% resizable images. Who must work in Muse CC 2016

  • Calculate the hours between 2 business days

    Hi all

    Do a complex calculation on the days I do not know how to achieve this.

    Here is my case:

    I have a week of work with hours of work.

    Then there's this delivery time sheet for how long should be set an order ready to be delivered:

    Order1: max 5 hours of work

    Order2: max 8 working hours

    Order3: max 16 hours of work

    When an order is placed, the time of the order is recorded, and when an order has been set in ready to be delivered, this time is also registered.

    How to calculate the time difference between the time where an order has been placed and the time where the order has been on loan. Thereby also taking into account the working days and hours of work.

    Example: type order1 order was placed Tuesday at 15:00.

    Order has been fixed loan Wednesday at 14:00

    This means that to fix this ready order lasts 7 hours, which means that it is 2 hours time.

    CREATE TABLE REF_WORKDAYS
      (
        
        "WERKDAG"       VARCHAR2(15 ) NOT NULL ENABLE,
        "SOORT_WERKDAG" VARCHAR2(15 ) NOT NULL ENABLE,
        "BEGIN_TIJD"    VARCHAR2(10 ) NOT NULL ENABLE,
        "EIND_TIJD"     VARCHAR2(10 B) NOT NULL ENABLE,
        
      )
    

    Insert into REF_WORKDAYS (WERKDAG,SOORT_WERKDAG,BEGIN_TIJD,EIND_TIJD) values ('Monday','WORKINGDAY','08:00','16:00');
    Insert into REF_WORKDAYS (WERKDAG,SOORT_WERKDAG,BEGIN_TIJD,EIND_TIJD) values ('Tuesday','WORKINGDAY','08:00','16:00');
    Insert into REF_WORKDAYS (WERKDAG,SOORT_WERKDAG,BEGIN_TIJD,EIND_TIJD) values ('Wednesday','WORKINGDAY','08:00','16:00');
    Insert into REF_WORKDAYS (WERKDAG,SOORT_WERKDAG,BEGIN_TIJD,EIND_TIJD) values ('Thursday','WORKINGDAY','08:00','16:00');
    Insert into REF_WORKDAYS (WERKDAG,SOORT_WERKDAG,BEGIN_TIJD,EIND_TIJD) values ('Friday','WORKINGDAY','08:00','16:00');
    Insert into REF_WORKDAYS (WERKDAG,SOORT_WERKDAG,BEGIN_TIJD,EIND_TIJD) values ('Satrurday','WORKINGDAY','08:00','14:00');
    Insert into REF_WORKDAYS (WERKDAG,SOORT_WERKDAG,BEGIN_TIJD,EIND_TIJD) values ('Sunday','NOT-WORKINGDAY','08:00','16:00');
    
    COMMIT;
    

    create table glas_order
    
    (order_id number
    , order_desc varchar2(100) not null
    , order_type varchar2(10) not null
    , order_date date not null
    , order_ready date
    
    );
    

    Insert into GLAS_ORDER (ORDER_ID,ORDER_DESC,ORDER_TYPE,ORDER_DATE,ORDER_READY) values (1,'order bla','Order1',to_date('07-APR-15 09:00','DD-MON-RR HH24:MI'),to_date('08-APR-15 12:00','DD-MON-RR HH24:MI'));
    Insert into GLAS_ORDER (ORDER_ID,ORDER_DESC,ORDER_TYPE,ORDER_DATE,ORDER_READY) values (2,'order nice','Order1',to_date('14-APR-15 10:00','DD-MON-RR HH24:MI'),to_date('16-APR-15 16:00','DD-MON-RR HH24:MI'));
    Insert into GLAS_ORDER (ORDER_ID,ORDER_DESC,ORDER_TYPE,ORDER_DATE,ORDER_READY) values (3,'order ugly','Order2',to_date('18-APR-15 13:00','DD-MON-RR HH24:MI'),to_date('21-APR-15 09:00','DD-MON-RR HH24:MI'));
    
    COMMIT;
    

    Thank you

    Diana

    Select

    I like order_id

    such as length d

    order_type

    d decode(order_type,'Order1',5,'Order2',8)

    overtime

    of glas_order o

    model

    Reference r on

    (select

    WERKDAG w

    begin_tijd b

    e eind_tijd

    , (to_date (eind_tijd, 'HH24') - to_date (begin_tijd, 'HH24')) * 24 hard

    of ref_workdays

    where soort_werkdag = "WORKINGDAY")

    dimension (w)

    measures (b, e, hard)

    main m

    partition of (order_id I)

    size of (0 n)

    measures (0d, order_date, order_ready, cast (null as varchar2 (10)) as wday, order_type)

    iterate (1e6) rules until (iteration_number > = trunc(order_ready[0]) - trunc(order_date[0])))

    WDAY [0] = to_char (order_date [0] + iteration_number, 'FMDay', 'NLS_DATE_LANGUAGE = ENGLISH')

    , d [0] = d [0] +.

    case

    When trunc(order_date[0]) = trunc(order_ready[0]) - beginning and ready same day

    then presentv (r.b [wday [0]],)

    less (largest (order_ready [0], to_date (to_char (order_date [0], 'YYYYMMDD') | r.b [WDAY [0]], 'YYYYMMDDHH24:MI')), to_date (to_char (order_date [0], 'YYYYMMDD') | r.e [WDAY [0]],'YYYYMMDDHH24:mi'))))

    -bigger (to_date (to_char (order_date [0], 'YYYYMMDD') | r.b [WDAY [0]], 'YYYYMMDDHH24:MI'), least (order_date [0], to_date (to_char (order_date [0], 'YYYYMMDD') | r.e [WDAY [0]],'YYYYMMDDHH24:mi'))))))

    0) * 24

    When order_date [0] + iteration_number = order_date [0] - first day

    then presentv (r.b [wday [0]],)

    TO_DATE (to_char (order_date [0], 'YYYYMMDD') | r.e [WDAY [0]], 'YYYYMMDDHH24:MI')

    -bigger (order_date [0], to_date (to_char (order_date [0], 'YYYYMMDD') | r.b [WDAY [0]],'YYYYMMDDHH24:mi'))))

    0) * 24

    When trunc(order_date[0]) + iteration_number = trunc(order_ready[0]) - last day

    then presentv (r.b [wday [0]],)

    less (order_ready [0], to_date (to_char (order_ready [0], 'YYYYMMDD') | r.e [WDAY [0]],'YYYYMMDDHH24:mi'))))

    -to_date (to_char (order_ready [0], 'YYYYMMDD') | r.b [WDAY [0]], 'YYYYMMDDHH24:MI')

    0) * 24

    of another nvl (r.dur [wday [0]], 0)

    end

    )

    ORDER_ID DURATION ORDER_TYPE OVERTIME
    1 11 Order1 6
    2 22 Order1 17
    3 10 Order2 2

    Rewrittten party rules for readability purposes (more resources)

    measures (0d, order_date, order_ready, cast (null as varchar2 (10)) as to_date (null), (null) to_date, bd, order_type, wday ed)

    iterate (1e6) rules until (iteration_number > = trunc(order_ready[0]) - trunc(order_date[0])))

    WDAY [0] = to_char (order_date [0] + iteration_number, 'FMDay', 'NLS_DATE_LANGUAGE = ENGLISH')

    , comics [0] = to_date (to_char (order_date [0] + iteration_number, 'YYYYMMDD') | r.b [WDAY [0]], 'YYYYMMDDHH24:MI')

    , ed [0] = to_date (to_char (order_date [0] + iteration_number, 'YYYYMMDD') | r.e [WDAY [0]], 'YYYYMMDDHH24:MI')

    , d [0] = d [0] +.

    case

    When trunc(order_date[0]) = trunc(order_ready[0]) - beginning and ready same day

    then presentv (r.b [wday [0]],)

    less (largest (order_ready [0], [0] bd), ed [0])

    -Greatest (BD [0], least(ORDER_DATE[0],ED[0]))

    0) * 24

    When order_date [0] + iteration_number = order_date [0] - first day

    then presentv (r.b [wday [0]],)

    ED [0]

    -Greatest(ORDER_DATE[0],BD[0])

    0) * 24

    When trunc(order_date[0]) + iteration_number = trunc(order_ready[0]) - last day

    then presentv (r.b [wday [0]],)

    least(order_ready[0],ED[0])

    -bd [0]

    0) * 24

    of another nvl (r.dur [wday [0]], 0)

    end

    )

    Jubilee should be Saturday I guessed.

  • Excerpt from the hours between two dates

    Hello

    This is the value stored in the table of my database.

    I want to extract betwwen hours two dates. How can I extract it.

    I try to run like this

    Select to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM') double, but it gives the answer as the format 21:10:00.000000000 + 000000365

    I want simple hours, minutes, and seconds

    What is the format of this value as "dd-MON-yy."

    27 JANUARY 14 01.30.00.000000 PM

    26 JANUARY 14 06.22.32.170033 PM

    Use the Extract function. Like this.

    () AS T1 (C1)

    Select to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM') of double)

    SELECT EXTRACT (DAY OF C1) | ' DAYS '.

    EXTRACT (HOUR OF C1) | ' HOURS '.

    EXTRACT (MINUTE OF C1) | ' MINUTES '.

    EXTRACT (SECOND C1) | ' SECONDS

    FROM T1;

    OUTPUT:

    365 DAYS 21 HOURS 10 MINUTES 0 SECONDS

    If not try it.

    SELECT EXTRACT (DAY OF to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM')) | ' DAYS '.

    EXTRACT (HOUR FROM to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM')) | ' HOURS '.

    EXTRACT (to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM') MINUTE) | ' MINUTES '.

    EXCERPT ((SECOND from to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM')) |) ' SECONDS

    DOUBLE;

    Post edited by: Parth272025

  • How to find the hours between two times

    Hai All

    I had a problem I need to calculate work time

    For example

    Respondent outtime

    0815 1715

    So I need to calculate a time between these two times

    How can I do using function for 100 our

    Concerning

    Srikkanth.M

    Hello

    use the below the update statement.

    update dail_att set wtime =  extract(hour from (to_date(outtime,'HH24:MI')-to_date(intime,'HH24MI')) day to second);
    

    Solution of the sample...

    PRAZY@11gR1> desc dte;
     Name            Null?    Type
     ------------------- -------- --------
     INTIME           VARCHAR2(4)
     OUTTIME        VARCHAR2(4)
     HRS                NUMBER
    
    PRAZY@11gR1> select * from dte;
    
    INTIME     OUTTIME           HRS
    ---------- ---------- ----------
    0815       1715
    0900       1800
    0830       1630
    
    Elapsed: 00:00:00.00
    PRAZY@11gR1> update dte set hrs = extract(hour from(to_date(outtime,'HH24MI')-to_date(intime,'HH24MI')) day to second);
    
    3 rows updated.
    
    Elapsed: 00:00:00.01
    PRAZY@11gR1> select * from dte;
    
    INTIME     OUTTIME           HRS
    ---------- ---------- ----------
    0815       1715                9
    0900       1800                9
    0830       1630                8
    
    Elapsed: 00:00:00.00
    

    Kind regards
    Prazy

    Published by: Prazy on March 24, 2010 12:43

  • Check the number of non zero values in each row

    Hello

    I have the following table

    create the table attbon as

    (

    Select pryear 2014, 1 empid, to_date('21/11/2014','dd/mm/yyyy') prdate, 12 prmonth, 3 shortleave union double all the

    Select double union all the 12 prmonth 2014 pryear, 1 empid, to_date('22/11/2014','dd/mm/yyyy') prdate shortleave 0

    Select double union all the 12 prmonth 2014 pryear, 1 empid, to_date('23/11/2014','dd/mm/yyyy') prdate shortleave 0

    Select double union all the 12 prmonth 2014 pryear, 1 empid, to_date('24/11/2014','dd/mm/yyyy') prdate shortleave 0

    Select double union all the 12 prmonth 2014 pryear, 1 empid, to_date('25/11/2014','dd/mm/yyyy') prdate shortleave 0

    Select pryear 2014, 2 empid, to_date('21/11/2014','dd/mm/yyyy') prdate, prmonth 12, 1 shortleave Union double all the

    Select 2014 pryear, 2 empid, to_date('22/11/2014','dd/mm/yyyy') prdate, prmonth 12, 1 shortleave Union double all the

    Select 2014 pryear, 2 empid, to_date('23/11/2014','dd/mm/yyyy') prdate, prmonth 12, 1 shortleave Union double all the

    Select double union all 12 prmonth, 2014 pryear, 2 empid, to_date('24/11/2014','dd/mm/yyyy') prdate shortleave 0

    Select double union all 12 prmonth, 2014 pryear, 2 empid, to_date('25/11/2014','dd/mm/yyyy') prdate shortleave 0

    Select 3-shortleave, 3-empid, prmonth 12, to_date('21/11/2014','dd/mm/yyyy') prdate, 2014 pryear Union double all the

    Select double union all 12 prmonth, 3 empid, to_date('22/11/2014','dd/mm/yyyy') prdate, 2014 pryear, 1 shortleave

    Select double union all 12 prmonth, 3 empid, to_date('23/11/2014','dd/mm/yyyy') prdate, 2014 pryear, 0 shortleave

    Select double union all 12 prmonth, 3 empid, to_date('24/11/2014','dd/mm/yyyy') prdate, 2014 pryear, 0 shortleave

    Select double union all 12 prmonth, 3 empid, to_date('25/11/2014','dd/mm/yyyy') prdate, 2014 pryear, 0 shortleave

    Select pryear 2014, empid 4, to_date (' 21/11/2014 ',' dd/mm/yyyy') prdate, prmonth 12, 1 shortleave Union double all the

    Select 2014 pryear, 12 prmonth, 3 shortleave, 4 empid, to_date (' 22/11/2014 ',' dd/mm/yyyy') prdate of all the double union

    Select double union all 12 prmonth, 2014 pryear, 4 empid, to_date('23/11/2014','dd/mm/yyyy') prdate shortleave 0

    Select double union all 12 prmonth, 2014 pryear, 4 empid, to_date('24/11/2014','dd/mm/yyyy') prdate shortleave 0

    Select pryear 2014, prmonth 12, shortleave 0, empid, to_date (' 25/11/2014 ',' dd/mm/yyyy') 4 prdate double

    );

    I want to find the eligibility of premium participation for each employee for each day

    An employee is allowed to take the maximum of 3 hours as shortleave.

    Normally if SHORTLEAVE is greater than 1 for a day, the employee is not eligible for the bonus of participation for this day

    So if an employee DISP shortleave of one hour each, on three different days or more, it is eligible for the bonus of attendance for every day.

    If it make use of all three hours on a stretch as he is eligible for the bonus of presence condition no other short-term leave availed for this month.

    otherwise this day where it's not eligible for the bonus of presence

    That is to say.

    attboneligible of a day is 1

    If shortleave < = 1

    or

    (shortleave = 3, and County of short leave zero for the month is 1)

    Required result

    =============================================

    EMPID PRDATE ATTBONELIGIBILITY

    =============================================

    21/11/2014 1, 1

    22/11/2014 1, 1

    23/11/2014 1, 1

    24/11/2014 1, 1

    25/1/11/2014 1

    21/11/2014 2, 1

    22/11/2014 2, 1

    23/11/2014 2, 1

    24/11/2014 2, 1

    25/2/11/2014 1

    3                 21/11/2014                     0

    22/11/2014 3, 1

    23/11/2014 3, 1

    3 24/11/2014 1

    25/3/11/2014 1

    21/11/2014 4, 1

    22/11/2014 4, 0

    23/11/2014 4, 1

    24/11/2014 4, 1

    25/4/11/2014 1

    ===============================================

    I use oracle 10g

    Help, please

    Hello Krishna,

    Try this in your test data:

    Update attbon set shortleave = 2 where shortleave = 3;

    And compare with your expectations.

    I guess, Frank or your own modiifcation will do the job...

    If I understand you right...

    But try Indra!

    Best regards

    Karlheinz

  • How to check the account of a column value is less than the other value of column in a table with a single column

    Hello

    Please let me know how to query the table and get the records that are less than the other column.

    ID item_id item_type

    3     1           r1

    2 4 r2

    1 5 r3

    6 5 r4

    I need to get all the lines in which item_id < id

    o/p

    ID item_id item_type

    3     1           r1

    6 5 r4

    SELECT ID, ITEM_ID, ITEM_TYPE

    Of

    WHERE ITEM_ID<>

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

  • Number of hours of the weekend between two timestamps

    I'm trying to take two timestamps and the total number of hours weekend between them.  For example:

    Between October 23, 13 08.28.00.000000 AM and 28 October 13 04.48.25.424940 PM, there are two weekend days.  I want the query to return the 48 hours.

    Between October 24, 13 04.48.25.424940 PM and 01.00.00.000000 October 27, 13 h ago weekend day plus 13 hours Sunday, I would that this return to 37 hours.

    Database version:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    "CORE 11.2.0.3.0 Production."

    AMT for Linux: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    Create / Insert statements:

    CREATE TABLE 'TDIFF.

    (NUMBER OF 'ID',

    "TS1' TIMESTAMP (6).

    ('TS2' TIMESTAMP (6));

    Insert into TDIFF (ID, TS1 and TS2) values (1, to_timestamp (17 October 13 02.09.01.818304000 PM ',' DD-MON-RR HH.MI.)) PSM AM FF'), to_timestamp (30 October 13 09.16.00.000000000 PM ',' DD-MON-RR HH.MI.) PSM AM FF '));

    Insert into TDIFF (ID, TS1 and TS2) values (2, to_timestamp (21 October 13 01.23.58.258494000 PM ',' DD-MON-RR HH.MI.)) PSM AM FF'), to_timestamp (24 October 13 10.00.00.000000000 AM ',' DD-MON-RR HH.MI.) PSM AM FF '));

    Insert into TDIFF (ID, TS1 and TS2) values (3, to_timestamp (07.33.10.874721000 AM October 23, 13 ',' DD-MON-RR HH.MI.)) PSM AM FF'), to_timestamp (24 October 13 10.00.00.000000000 AM ',' DD-MON-RR HH.MI.) PSM AM FF '));

    Insert into TDIFF (ID, TS1 and TS2) values (4, to_timestamp (09.12.41.928313000 AM October 23, 13 ',' DD-MON-RR HH.MI.)) PSM AM FF'), to_timestamp (25 October 13 02.30.00.000000000 PM ',' DD-MON-RR HH.MI.) PSM AM FF '));

    Insert into TDIFF (ID, TS1 and TS2) values (5, to_timestamp (10.12.22.790736000 AM October 23, 13 ',' DD-MON-RR HH.MI.)) PSM AM FF'), to_timestamp (24 October 13 06.40.00.000000000 PM ',' DD-MON-RR HH.MI.) PSM AM FF '));

    Insert into TDIFF (ID, TS1 and TS2) values (6, to_timestamp (10.33.20.879307000 AM October 23, 13 ',' DD-MON-RR HH.MI.)) PSM AM FF'), to_timestamp (25 October 13 04.24.00.000000000 PM ',' DD-MON-RR HH.MI.) PSM AM FF '));

    Insert into TDIFF (ID, TS1 and TS2) values (7, to_timestamp (11.01.23.467642000 AM October 23, 13 ',' DD-MON-RR HH.MI.)) PSM AM FF'), to_timestamp (24 October 13 07.00.00.000000000 AM ',' DD-MON-RR HH.MI.) PSM AM FF '));

    Insert into TDIFF (ID, TS1 and TS2) values (8, to_timestamp (23 October 13 04.45.08.237177000 PM ',' DD-MON-RR HH.MI.)) PSM AM FF'), to_timestamp (07.00.00.000000000 AM October 25, 13 ',' DD-MON-RR HH.MI.) PSM AM FF '));

    Insert into TDIFF (ID, TS1 and TS2) values (9, to_timestamp (23 October 13 04.48.25.424940000 PM ',' DD-MON-RR HH.MI.)) PSM AM FF'), to_timestamp (28 October 13 08.28.00.000000000 AM ',' DD-MON-RR HH.MI.) PSM AM FF '));

    This is what I have so far, but his return the number of incorrect hours:

    SELECT TS1,TS2,
      (SELECT COUNT(*)
       FROM DUAL
       WHERE TO_CHAR(TS2 + LEVEL - interval '1' hour, 'DY') IN ('SAT', 'SUN') 
    CONNECT BY LEVEL <= 24*extract(DAY FROM TS2-TS1)+extract(hour FROM TS2-TS1) + 1 ) D1_WEEKEND_HOURS
    FROM TDIFF
    

    Any ideas are appreciated.

    -Steve

    Here is another way, assuming a definition of the weekend as strictly between midnight Friday and midnight Sunday:

    The interval of D1 to D2 can be considered be allowed between the D1 and the next 00 Monday more time between Monday preceding the D2 and D2 as well as the weeks between the two Monday to 00:00.

    select  id, ts1, ts2,
    ( least(7 + (trunc(CAST(ts1 as DATE), 'IW') - CAST(ts1 as DATE)), 2) /* ts1 to Monday */
    + greatest( (CAST(ts2 as DATE) - trunc(CAST(ts2 as DATE), 'IW')) -5, 0) /* Monday to ts2 */
    + 2/7 * (trunc(CAST(ts2 as DATE), 'IW') - trunc(CAST(ts1 as DATE), 'IW') -7 ) /* Weeks between Mondays */
    ) * 24
    from TDIFF
    
  • The sound of Apple received email saying and tells me to check the password within 48 hours.  Scam?

    rreceived 'Apple' email, telling me to check the password within 48 hours.    Is it a scam?

    Yes, it's almost certainly a scam.

    The only time where Apple will send you a letter about your password is if you click on the "Forgot password" link on one of their sites, and even in this case the email will tell you how change or reset, has not check.

  • Take the time between two values

    Hi people,

    I have a problem and I know idea how to solve... I need help.

    The problem is I want to take the time between two values max as you can see in the chart.

    For example, in the image that I have add

    4.5 - 1 840 = 2.66

    And enter this value in the 'time between mostra '.

    It's that I want...

    But what I think is very complicated, because I don't know how to take the time correctly and does remove...

    Thank you very much

    Any solution?

    Hi jocuma,

    I tried something and hope that helps u.

    Just create two arrays of temperature and voltage. First of all, I'll get the value of the voltage when it is more of a certain value and that same index to get the value of time and store in the shift register.

    When I get the second higher than the limit value, I'll get time and subtract the previous value.

Maybe you are looking for

  • Bootcamp deleted

    To rid my macbook pro for windows 10, I am about this the wrong way and removed Bootcamp. Now I find that I can not manage to restore the partition deleted on the Mac HD. Any help to solve this appreciated.

  • What thermal paste works well for Satellite A200?

    Hello I have the problem of heat for months. I have tried serval OCZ Freeze extreme conductivity compound thermal times there worked in the first week. But the second week, it became worse and worse until the laptop could not start. Someone has sugge

  • Bypass SequenceFileLoad

    TestStand 4.1, we have a problem with a step in a sequence SequenceFileLoad recall that kills the editor. I tried to turn on tracing everything to see what the cause of the problem but TestStand does not display the executions of SequenceFileLoad. I

  • Open a project (first instance) of Premiere Elements in first Pro CC (full)

    A Department in my company has recently started producing promotional videos, as they initially had no video editing software they tested several programs before finally settling for first Pro CC.The question I have is that in the meantime the Depart

  • installation of sql developer

    HelloI have a 64-bit version of windows 7. I also have jre (java runtime environment) installed on my pc. I have Oracle database 11g XE installed on my pc.I want to install sql developer. should what version of sql developer I install? version 32-bit