Compare Timestamp with a number in hours

Hi,
Need help with this question.
I want compare a timestamp with a value like 24 or 36 hour.
For example:
Timestamp: '16-jul-2010 13:00:00' when the 24 hours is pass ('17-jul-2010 13:05:10') then I want to update a table.
Is it possible to to this in pl/sql or have Oracle 11G a function in it.
I appreciate some help.
Thanks.

Having article_id in both tables you could try something like (not tested as I don't have database access)
update table_1 t1
   set result = 1
where 24 * (sysdate - timestamp_placed) > (select time
                                              from table_2
                                             where article_id = t1.article_id
                                           )Regards
Etbin
sorry (working doing it from home and someone posted a not completed template)
Try to do it with a single update or else ... - you'll hear from damorgan ;)
update gkr_droogkamer1 dgr
   set result = 1
where result = 0
   and 24 * (sysdate - timestamp_placed) > (select dry_time
                                              from gkr_artikel
                                             where article_id = dgr.article_id
                                           )You'd better come up with a data sample and someone will provide a tested solution asap. Something like:
create table gkr_droogkamer1
select 1 article_id,sysdate - 50 / 24 timestamp_placed,1 result from dual union all
select 2 article_id,sysdate - 40 / 24 timestamp_placed,0 result from dual union all
select 3 article_id,sysdate - 30 / 24 timestamp_placed,0 result from dual union all
select 4 article_id,sysdate - 20 / 24 timestamp_placed,0 result from dual union all
select 5 article_id,sysdate - 10 / 24 timestamp_placed,0 result from dual;
create table gkr_artikel
select 1 article_id,36 dry_time from dual union all
select 2 article_id,36 dry_time from dual union all
select 3 article_id,24 dry_time from dual union all
select 4 article_id,24 dry_time from dual union all
select 5 article_id,24 dry_time from dual;Regards
Etbin
Edited by: Etbin on 20.7.2010 16:10

Similar Messages

  • Subtracting two timestamps and showing the number of hours between them.

    Hello Folks,
    What I have is two tables, each of them has a timestamp column. I want to do a select with a join that will show a column with the number of hours between the two times.
    (I have added the columns as timestamp(0) since I have no need for the decimals)
    Here's what I have:
    table one name: conc_test
    table one info:
    P_DATE-------JOB_NO-----MIX---POUR_NO----AMB_T---CONC_T--SLUMP---AIR---DENSITY---CYL_CAST_TIME
    09-MAR-10---9-12-796-----80----100309A------2.5--------16----------135------2.5----2501-------09-MAR-10 10.00.00 AM
    table two name: rls_break
    table two info:
    JOB_NO----POUR_NO-----CYL_ID----SPEC_STR---STR----MIX---BREAK_D_T
    9-12-796---100309A----100309A1------20-----------27-----80----10-MAR-10 07.15.00 AM
    (I put the --- between the columns so it would be more legible for forum reading, fyi)
    This is what I was trying to do:
    select
    rls_break.cyl_id "Cylinder ID",
    rls_break.mix "Mix",
    trunc(rls_break.break_d_t-conc_test.cyl_cast_time) "Age",
    rls_break.spec_str "Specified Strength",
    rls_break.str "Specimen Strength"
    from rls_break inner join conc_test on rls_break.pour_no = conc_test.pour_no
    where pour_no = '100309A';
    I want the "Age" column to show the total number of hours between the cast time (column cyl_cast_time from conc_test) and the break time (column break_d_t from rls_break)
    Thank's for any and all help.

    (I put the --- between the columns so it would be more legible for forum reading, fyi)Please put the tag before and after your examples.
    See: http://forums.oracle.com/forums/help.jspa for more information reagarding tags. (scroll a bit down)
    I want the "Age" column to show the total number of hours between the cast time (column cyl_cast_time from conc_test) and the break time (column
    break_d_t from rls_break)
    Do a search on 'NUMTODSINTERVAL' or 'time difference' on this forum, you'll find many related examples.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • "You can't compare a date with a number" in a formula that worked in Excel

    I opened in Numbers an invoice file which was created in Excel. Formula returns hours worked. It has an "if" condition for the date field. I am assuming that that is the reason I get this "You can’t compare a date with a number because their data types are different." What do I do?
    Formula reads =IF(SUM(A11)>0,(D11−C11),"") where A11 is a date and D11- C11 are times, ie 4PM and 5PM
    Message was edited by: iamzoran

    Jerrold Green1,
    I agree with your words about using Sum with a single cell [have no idea why the "creator" of the file did that]; same for the parentheses enclosing subtraction. Yet cleaning it up as you showed me [=IF(A11>0,D11−C11,"") ] I got the same comment
    "You can’t compare a date with a number because their data types are different."
    Makes me think that t quinn is on to something with his "think the issue is with the expression ">0". Could it be that >0 is the number referred to and <>"" and ISBLANK are not numbers?!
    z
    PS: I am so happy that I am able to use Spelling and Grammar Checker with Safari on these posts. I was born and raise in old Yugoslavia and I use the Checker with all my emails etc and its a life saver. hahaha

  • Trying to compare item with number in PL/SQL report

    Hi,
    I'm using for my report SQL Query (PL/SQL Function body returning SQL Query). And I found that I can't to write:
    if v('ITEM_NAME')=1 then ..., because it is 'missing expression' error.
    I can only
    if v('ITEM_NAME') IS NULL then ...
    or
    if v('ITEM_NAME') IS NOT NULL then ...
    Why I can't to compare item value, for example, with number?
    Thanks!
    Karina.

    Hi,
    I'm using my own htmldb installation. The reports' code is:
    DECLARE
    q varchar2(10000);
    v_lesst_str varchar(255);
    v_lesst_stmt_2 VARCHAR2(100):='select lesst_id from lesson_types';
    v_meas_str varchar(255);
    v_meas_stmt_2 VARCHAR2(100):='SELECT meas_id FROM project_measures';
    BEGIN
    if v('P16_LESSONS_TYPE') is null THEN v_lesst_str:=v_lesst_stmt_2;
    ELSE v_lesst_str:=v('P16_LESSONS_TYPE');
    END IF;
    if v('P16_PRO_MEASURE') is null THEN v_meas_str:=v_meas_stmt_2;
    ELSE v_meas_str:=v('P16_PRO_MEASURE');
    END IF;
    q:='SELECT distinct ul.title, ul.summary, ul.details, ul.less_id
    FROM user_lessons ul
    WHERE ul.lesst_lesst_id IN ('||v_lesst_str||')
    AND ul.meas_meas_id IN ('||v_meas_str||')';
    return q;
    END;
    The error is occurred when I'm trying to compare item with number, for example, v('P16_LESSONS_TYPE')=1 in if condition.
    And the errors' text is next:
    "#1 error has occurred
    Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. ORA-00936: missing expression"
    Karina.

  • Hi im having difficulty with my iphone 4s its been on charge for a number of hours and continues to flash the apple logo but will not turn on i have tried to reset but it did not help

    hi i am having difficulty with my iphone 4s it has been on charge for a number of hours but is just flashing the apple logo continuously i have tried to reset but nothing seems to work can anyone help me please

    What is a hard reset?  There is nothing in any of Apple's documentation that refers to a hard reset.
    There's a reset, a restart, and a restore.
    Please explain EXACTLY what you did.

  • How to compare varchar with number

    i am doing one report for that am passing receipt number(from , to) as parameters
    if i compare for that table i am getting output.
    select receipt_num from rcv_shipment_headers rsh
    where to_number(rsh.receipt_num) between nvl(:P_RECEIPT_FROM,rsh.receipt_num) and nvl(:P_RECEIPT_TO,rsh.receipt_num)
    but when i am using in below query it is getting error "Invalid Number"
    select rsh.receipt_num
    , sum(rs.quantity)
    , rs.unit_of_measure
    , rct.transaction_date "Date of Entry"
    , pov.vendor_name
    , msi.segment1 "Item Code"
    , msi.description "Item Description"
    from rcv_transactions rct
    , rcv_shipment_headers rsh
    , rcv_shipment_lines rsl
    , po_vendors pov
    , mtl_system_items_b msi
    , rcv_supply rs
    where rsh.shipment_header_id=rct.shipment_header_id
    and rsh.shipment_header_id=rsl.shipment_header_id
    and rsl.shipment_line_id=rct.shipment_line_id
    and rsh.vendor_id=pov.vendor_id
    and rsl.item_id=msi.inventory_item_id
    and msi.organization_id=106
    and rsl.shipment_line_id=rct.shipment_line_id
    and rct.transaction_id=rs.rcv_transaction_id
    and to_number(rsh.receipt_num) between nvl(:P_RECEIPT_FROM,rsh.receipt_num) and nvl(:P_RECEIPT_TO,rsh.receipt_num)
    and rct.organization_id=nvl(:P_ORG_ID,rct.organization_id)
    and rsh.vendor_id=nvl(:P_Vendor_Name,rsh.vendor_id)
    and rct.inspection_status_code='NOT INSPECTED'
    group by rsh.receipt_num
    , rs.unit_of_measure
    , rct.transaction_date
    , pov.vendor_name
    , msi.segment1
    , msi.description
    plese help to solve
    Thanks & Regards
    Adina

    The problem lies here:
    and rsh.vendor_id=nvl(:P_Vendor_Name,rsh.vendor_id)How can you compare vendor_name with vendor_id????????????
    SQL> select * from po_vendors where vendor_id = NVL(&p_vendor_name,vendor_id);
    Enter value for p_vendor_name: 'AAAA'
    old   1: select * from po_vendors where vendor_id = NVL(&p_vendor_name,vendor_id)
    new   1: select * from po_vendors where vendor_id = NVL('AAAA',vendor_id)
    select * from po_vendors where vendor_id = NVL('AAAA',vendor_id)
    ERROR at line 1:
    ORA-01722: invalid number
    SQL> Message was edited by:
    user605919

  • How to configure JSpinner to accept number of hours (with mins and secs)

    I'm having a problem trying to figure out a simple way to enable a JSpinner to do allow the input in this format:
    n hours : n minutes : n seconds
    ex: 100 : 0 : 0, 1:59:59, 25:30:00
    Where n hours could be from 0-n (not restricted by 24 hours) and minutes and seconds are, of course, < 60. That is, I can enter number of hours, not a date, or a specific time in a day.
    I'm thinking the only way to do this is with a custom spinner model and custom editor? Or is there a simple way I can make the date model in spinner to allow me to do this?
    Thanks

    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    public class Test2 extends JFrame {
      public Test2() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        content.setLayout(new FlowLayout());
        content.add(new MySpinner());
        setSize(300, 300);
        setVisible(true);
      public static void main(String args[]) { new Test2(); }
    class MySpinner extends JSpinner {
      public MySpinner() {
        setModel(new SpinnerDateModel(
          new GregorianCalendar(2004,0,1,0,0,0).getTime(),
          null, null, Calendar.DAY_OF_YEAR));
        setEditor(new DateEditor(this,"HH:mm:ss"));
    }???

  • Compare date with timestamp

    I have data in timestamp format like 10/06/2009 11:59:01 PM EDT. I need to compare it with sysdate after removing the PM EDT etc.
    I tried to_date, trunc etc... nothing worked. Is there a way to remove that PM EDT and compare with sysdate.

    Hi,
    What problem you face when you directly compare timestamp column with sysdate?
    select cast (systimestamp as timestamp with local time zone) -sysdate from dual;
    CAST(SYSTIMESTAMPASTIMESTAMPWITHLOCALTIMEZONE)-SYSDATE
    +000000000 00:00:00.481609Regards
    Anurag Tibrewal.

  • Compare 2 'timestamp with timezone' columns

    Hi All,
    I'm trying to compare 2 'timestamp with timezone' columns,
    comparision works fine as long as there is difference of at least seconds between them.
    But when the difference between them is in milliseconds, comparison is failing.
    I'm using oracle 10g.
    Pls advice.

    Works just fine:
    SQL> DECLARE
      2      t1 TIMESTAMP WITH TIME ZONE := TIMESTAMP '2008-01-10 10:25:17.123456 US/EASTERN';
      3      t2 TIMESTAMP WITH TIME ZONE := TIMESTAMP '2008-01-10 10:25:17.323456 US/EASTERN';
      4  BEGIN
      5      IF t1 <= t2
      6        THEN
      7          DBMS_OUTPUT.PUT_LINE('t1 <= t2');
      8      END IF;
      9  END;
    10  /
    t1 <= t2
    PL/SQL procedure successfully completed.
    SQL> DECLARE
      2      t1 TIMESTAMP WITH TIME ZONE := TIMESTAMP '2008-01-10 10:25:16.123456 US/EASTERN';
      3      t2 TIMESTAMP WITH TIME ZONE := TIMESTAMP '2008-01-10 10:25:17.323456 US/EASTERN';
      4  BEGIN
      5      IF t1 <= t2
      6        THEN
      7          DBMS_OUTPUT.PUT_LINE('t1 <= t2');
      8      END IF;
      9  END;
    10  /
    t1 <= t2
    PL/SQL procedure successfully completed.
    SQL> Based on your:
    But when the difference between them is in milliseconds, comparison is failing. Most likely your code does implicit/explicit timestamp conversion to date. Post your code.
    SY.

  • How do I list the last n number of hours with respect to sysdate?

    I had a query regarding listing the last n number of hours with respect to sysdate?
    Say the current time is 1 AM, I want to get an output in the below format:
    1 AM
    12 AM
    11 PM
    10 PM
    9 PM...
    I know I can do it using a simple begin end block but I want the output to be returned in one single query.
    Any help would be very appreciated..

    Thanks!!
    I just figured it out as well!
    I used this:
    with hour_list as
         select trunc(sysdate- level/24,'HH') ,rownum
         from dual
         connect by level <=8
    select * from hour_list;

  • Attempt to compare nil with number

    When trying to open a plugin via File->Plugin-extra for a missing photo, a message "Sorry, Lightroom could not complete your request. The reason code appears below: ?:0: attempt to compare nil with number". Plugin was Photo Frame 4.6 from OnOne Software. Same happens when opening any plugins of the same 5.5 Suite.
    MAC OS 10.6.5, Lightroom 3.3.

    The plugin could be intending to interact with image metadata or something else, which is still present even if the physical image file is missing. That is, a plugin may not need actual access to a managed image file.
    If I understand what you are doing correctly, Lr has no idea what the plugin is going to do with the reference it has been handed. It knows the target file is missing and should have updated the UI to indicate this, but this does not really have anything to do with what some arbitrary plugin might do with an API reference to this same managed image.
    It looks like the error is being thrown in the plugin Lua code, and Lr is just reporting this fact. The plugin might want to check that the API ref it has been handed is actually sound, and recover more gracefully instead of assuming that the managed image file actually exists.
    [Later]
    For example, a plugin can use the photo:checkPhotoAvailability() API call since v2.0 to determine if the photo is believed to be present on disk.

  • Trying to compare FCP with Media 100 for a Public Access studio

    Hi all,
    I am new here. I do most of the review of products for our Public Access studio. We have a couple of existing Media 100 systems and we are considering adding or upgrading our NLE capabilities. Our studio manager had a chance to look at FCP being used at our high school and she came back with a number of impressions that I wonder about and would like to vet with people who know more about FCP. So, any comments would be helpful.
    The high school media person demo’d FCP for her and let her play with it a bit. After looking at it herself, she says she would definitely say Media 100 is easier to understand/use, especially if you've never used non-linear editing before. That is fairly typical of the people doing Public Access production in our town.
    However, it looks to her like there are a lot of tools that come with FCP that Media 100 either doesn't have or are not easily found in it. For example, she feels FCP’s set up looks more complicated and confusing compared to Media 100’s, but in FCP you can have up to 99 video lines in a program, where with Media 100 we're just going back and forth between the a and b video lines. Plus you can have up to 99 Audio tracks on FCP as well, where our max at the moment is 8. Now as to when you would need 99 video or audio tracks, she is not sure, but it is definitely a capability that we don't have in Media 100.
    Titling looked easier to her on Media 100. With FCP there were a lot of filters involved and hoops to jump through, plus she couldn't do a word with each letter a different color, for example, unless she did each letter on a different track.
    The media person warned her that FCP is really large. Apparently the program itself takes up like 35 GB of space on the hard drive, and a typical 30 min. project comes in at over 100 GB! She couldn't believe it, but she was assured it’s true. Even with our longest programs, like like a School Committee meeting thqat went 3 1/2 hours, it would came in at a max of 30 GB on the Media 100. She got the impression this big difference was so because Final Cut renders everything you do, including rendering any edits you make on your footage as new files, and stores it all in a huge folder. She thinks with Media 100, you import the footage and use it as is - the only things it will render are screen freezes, transitions, and color effects. Is that sort of comparison correct (and fair), or is something being missed?
    She says in her experience that something like iMovie is the most basic as far as what you can do, then Ulead would be a step above that- the editing is basically the same, but you have a few more options. Media 100 would be next as far as ease of use and understanding of the program. FCP seemed a little confusing even to her. Comments or insights?
    G4   Mac OS X (10.4.7)  

    Welcome to the family, maybe.
    I switched from M100 about four years ago, I was never so glad to give that company the boot. A direct comparison just isn't possible but I'll try to answer some questions. There is a Media 100 forum on creativecow.net.
    she says she would definitely say Media 100 is easier to understand/use, especially if you've never used non-linear editing before.< </div>
    Yes, absolutely, M100 has always had an elegant and refined interface. However, the paradigm in FCP is not opaque. It's far more interesting, deeper, more complex. So, yes, it's a bit tougher to grasp. But don't sell your students/users short. They'll get it.
    99 tracks is marketing BS. The serious work is done with nesting. How many public access pieces need more than 5 or 10 video tracks?
    Titling in FCP depends on third party filters like Boris or tools like LiveType and Motion. The basic titling tools in FCP are lame and difficult to use, in my opinion, compared to the elegant titler in M100 (as long as you don't launch Graffiti).
    The installation includes tens of gigs of animation, movie and music loop resources that you don't need to load. The suite includes Motion, LiveType, Soundtrack Pro, DVD Studio Pro and FCP.
    If you're shooting DV, a 3-1/2 hour show is, umm, well, you look it up, DV is DV. But if you're capturing 3 hours from each of three cameras, that's a lot of DV.
    Rendering depends on lots of things. M100's native codec handles lots of realtime stuff that FCP can't unless you've got a huge Macintosh. Previewing is not a big deal at lower rez in FCP, you get used to it. .
    FCP is really scary. You can look at thousands of "I'm in way over my head, HELP!" posts here. But all those folks find they slip right into the Apple paradigm, the weirdly new workflow and start exploring the wide new world of serious editing that FCP opens up. You'll hate it for a few months because it's so dramatically different from M100. You'll love it, though.
    If you want to continue the thread, give the rest of the disaffected former M100 users a few days to post their comments. There are many of us here. Then maybe start a new thread, one question at a time.
    bogiesan

  • Delete rows older than given number of hours

    Hi,
    I have a table student which contains the following columns
    ID Number(5)
    Name varchar2(20)
    Strt_Time timestamp(6)
    Strt_time is the timestamp when the particular row is inserted in the table.
    I need a query to delete all the rows inserted before given particular number of hours.
    For Example. If i pass the input paramter as 2 all the rows inserted before 2 hours from now should get deleted.

    Hi,
    Here's one way:
    DELETE  student
    WHERE     strt_time < SYSTIMESTAMP - INTERVAL '2' HOUR
    ;Or, if you're getting a NUMBER parameter like :num_hours, then
    DELETE  student
    WHERE     strt_time < SYSTIMESTAMP - NUMTODSINTERVAL (:num_hours, 'HOUR')
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
    In the case of a DML operation (such as DELETE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table after the DML.
    Explain, using specific examples, how you get those results from that data.
    If your results depend on the current time and/or parammeters, then give a couple of different examples using the same sample data. For example "If I run this at 11:00 on January 3, 2013, with :num_hours=12, then the table should be left with ... but if I run it at 13:00 on January 3, 2013, with :num_hours= 24, then I should get ..."
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Webform that opens with auto number

    I need a web form that opens with a 5 digit number auto assigned. Each new form will increase by one  digit. When submitted it sends to mysql db. All connections between form and mysql have been made and are working. Just have not  figured out how to open form with auto number. Any help would be appreciated.

    The problem with your plan is that everytime a user, spambot or any other person or bot opens your form, a number gets generated. This might be an argument for generating the number outside the database, using even a simple text file to store the numbers as they accumulate.The alternative would be to use  an auto_increment primary key in the database to generate the number. The problem with that approach is that your database will fill up with empty records that contain just the primary key.
    I think that the best solution is to simply not do what you are trying to do. I think it's a bad plan.
    If you were to use the database method, as soon as the page opens, run an insert query on the database to simply generate the number, then call the number from the database using either:
    id = mysql_insert_id(); ----with the original, bad mysql connection
    $dbh->lastInsertId()  ----with a PDO connection
    Then, after the form is filled out, use an update query with a where clause as so:
    update mytable set name = '$name'  (etc., etc.) WHERE id = '$id'
    As already pointed out, using this method, your table will populate with many rows that contain just the key number because many users and spambots that open the form will not complete it, or your validation will reject them, but you could run a trigger on your database to purge these empty records automatically, or, if you don't know how to create a trgger, you can run a query that simply says:
    DELETE from mytable WHERE somefield IS NULL AND timestamp > currenttime + 5 hours
    (the above the the query logic, not the actual finished query. You wouldn't want to delete all empty records because you may delete some where the user is still filling out the form, that's why you would give it a few hours between creation time and delete time.)
    So if you used the text file method, you would use the PHP fopen function to open the file, check for the last created number, add the next number to the list, and echo that number on your form. You would run this script at the top of your page.
    But I would really think hard about whether you really need to generate the number before the filled out form is submitted. Maybe you do, but avoid it if you can.

  • HI Team, Recently One week back I bought a new iphone 5 from India. They have given me a used mobile which has a different IMEI number when compared to the IMEI number present on the box. Please let me know how to proceed further

    HI Team, Recently One week back I bought a new iphone 5 from India. They have given me a used mobile which has a different IMEI number when compared to the IMEI number present on the box. Please let me know how to proceed further

    When you went back to the place where you purchased this phone, & asked them, what did they say?
    No one here can help you with this, nor can/will Apple. You need to take this up with whoever you purchased this phone from.

Maybe you are looking for

  • ITunes will not start up... Keeps giving Windows Error Message.... help!!

    My Itunes will not start at all... When I try to start it I get a Windows Error Message saying below: *iTunes has encountered a problem and needs to close. We are sorry for the inconvenience.* *In the Error Window The following is there...* _AppName:

  • I just downloaded the new iTunes and now receiving error message when I try to open iTunes!

    After downloading the new iTunes when I try to open it i receive the following error message: iTunes.exe - Entry Point Not Found Procedure entry point kCMByteStreamNotification_AvailableLengthChanges could not be located in the dynamic link librabry

  • Validate Numeric values in a varchar2 column

    Hi All, I am looking for some advise on the following approach. My Problem: I have a table test1( age varchar2(3) ); I have another table test2( Nage number ); I am trying to write a procedure which selects records from test1 validate that age column

  • Bold in AppWorks  vs Pages

    We are attempting to convert our usage from Appleworks to Pages and have run into a problem. A document we converted has a font called Baker Signet in it. We could bold or italics to our heart's content. When we bring it into Pages we can only have p

  • Mac osx 10.6 with sbs server 2003

    Hi everyone i m using mac osx 10.6 on my imac . i want to connect it with sbs server 2003 , then i want to to make a map drive on it .I m trying it to cmd+k to connect with server but it not connecting , i m wondring do i need to configure any thing