Subtracting two timestamps

Hi all

Thanks for looking

I'm subtracting (systimestamp - "TIME_IN") as "HOURS_WORKED".
(30/08/2010 16:42-30/08/2010 04:00) = "HOURS_WORKED".

the column called hours, the columns hours 'worked' shows '000000000 12:42:58.9881'

I understand that the hours are 12 hours and 42 minutes and 58 seconds.

is it possible that I can format this column to just show me hours and minutes?

of '000000000 12:42:58.9881' 12:42?

is there an easier way?

Thanks in advance

Published by: jo3y2 on August 30, 2010 17:19

Select double to_char(sysdate,'hh24:mi:ss')

or

SELECT TO_CHAR(date1,'MMDDYYYY:HH24:MI:SS') date1,
To_char(date2,'MMDDYYYY:HH24:mi:SS') date2,
trunc (86400 *(date2-date1))-60 * (trunc ((86400 *(date2-date1)) / 60)) seconds.
trunc ((86400 *(date2-date1)) / 60)-60 * (trunc (((86400 *(date2-date1)) / 60) / 60)) minutes,.
trunc (((86400 *(date2-date1)) / 60) / 60)-24 * (trunc (((86400 *(date2-date1)) / 60) / 60) / 24)) hours.
trunc (((86400 *(date2-date1)) / 60) / 60) / 24) days.
trunc (((86400 *(date2-date1)) / 60) / 60) / 24) / 7) weeks
OF date_table

See this post
http://www.databasejournal.com/features/Oracle/article.php/2234501/A-comparison-of-oracles-date-and-timestamp-datatypes.htm

Tags: Database

Similar Questions

  • Type of data resulting from the difference between two timestamps

    Hi, I have a simple question.
    I have two TIMESTAMP A and B variables. Now I want to subtract one B - A. What type of data as a result of this subtraction?
    Would Shouln t TIMESTAMP again?

    Consider this example:
    DECLARE
       vdat_Begin        TIMESTAMP;
       vdat_End          TIMESTAMP;
       vdat_Difference   TIMESTAMP;
    BEGIN
       vdat_Difference := vdat_End - vdat_Begin;   -- this doesn't work
       vdat_Difference := TO_TIMESTAMP(vdat_End - vdat_Begin);   -- this works
    END;
    /
    
    PLS-00382: expression is of wrong type
    Thanks for help.

    xxsawer wrote:
    Hi, I have a simple question.
    I have two TIMESTAMP A and B variables. Now I want to subtract one B - A. What type of data as a result of this subtraction?
    Would Shouln t TIMESTAMP again?

    Consider this example:

    DECLARE
    vdat_Begin        TIMESTAMP;
    vdat_End          TIMESTAMP;
    vdat_Difference   TIMESTAMP;
    BEGIN
    vdat_Difference := vdat_End - vdat_Begin;   -- this doesn't work
    vdat_Difference := TO_TIMESTAMP(vdat_End - vdat_Begin);   -- this works
    END;
    /
    
    PLS-00382: expression is of wrong type
    

    Thanks for help.

    No, as stated, there will be an interval.

  • When I subtract two numbers DBL and try to compare the result with another DBL, it fails

    I found a curious problem with subtraction and compare numbers DBL in LabVIEW (8.6). Here's how it works:

    1. subtract two numbers DBL such that the result is not incorporated. (Say, 3.2 - 3.1)

    2. compare the result with a constant/control that is on the result of the subtraction (in the example, 0.1)

    3 see the output of the comparison.

    If the result of the subtraction is an integer, the Boolean result is (as expected). If the result is not complete, the comparison fails.

    (Now, if I simply compare two floating point numbers, it works, so the issue is not with the node comparison itself, but with the data that is entered to the node). Can someone understand why this happens? It's unexpected, it's a pretty serious bug.

    It is provided with all programming languages. Numbers do not have an exact binary floating-point representation. This has been discussed endlessly. Never use the equal function with floats. You can use the function in the range and force.

  • Subtract two time_clock and get the result minutes

    Hi Experts,

    Nicely, I would subtract two type of time_clock that varcahr2 to the database and get the minutes of the result.

    Data:

    Select ' 08:00 ' as start_time_clock, 15:00 ' as the double end_time_clock

    Union of all the

    Select ' 09:00 ', 16:30 ' of the double

    Expected result:

    start_time_clock end_time_clock count_minutes

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

    08:00                      15:00                       420

    09:00                      16:30                       450

    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - production


    Thanks in advance

    WITH dataset

    AS (SELECT ' 08:00 ' AS start_time_clock, 15:00 ' AS end_time_clock)

    OF THE DOUBLE

    UNION ALL

    SELECT ' 09:00 ', 16:30 ' DOUBLE)

    SELECT (to_date (end_time_clock,'HH24:MI')-to_date(start_time_clock,'HH24:MI')) * 24 * 60))

    Of THE dataset

  • difference between two timestamps

    Hi gurus,

    I have a procedure which has 2 input parameters of type timestamp. I need to find the difference between these two stamps and be converted to a timestamp and return. Help, please

    Diifernce between two timestamps is interval. You can not convert the difference between two timestamp timestamp and it makes no sense. What you expect:

    25/06/2014 11:25:37.524000 - 13:07:22.987654 20/06/2014

    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
    
  • How to subtract two table of 1 d (uint16) same size

    I need to remove two 1 d (uint16) same size table. with output as follows...

    x - y = result (EXPECTED)

    5 - 2 = 3

    4 - 0 = 4

    0-4 = 0

    2 - 3 = 0

    If the difference is less than zero value must be zero. Currently, if I use the digital subtraction... I get...

    x - y = result (OBSERVED)

    5 - 2 = 3

    4 - 0 = 4

    0-4 = 4

    2 - 3 = 1

    Thank you

    Hello rajxabc,

    I don't know why you expect whole math unsigned to produce a 0 in the script show you below.  The U16 ends actually spent 0.

    Thus,.

    0-1 = 65535

    0-2 = 65534

    0-3 = 65533

    If you want to change the standard behavior of the unsigned integer math, you need to create a special algorithm for this, produce something like:

    There are a number of ways that you can accomplish this, but at the end of the day, I don't know that I would be the label none of them "expected."

  • How to subtract two fields in a form?

    I am working on a form of spending and I everything works except one thing.

    Subtract all on payments reports on previous expenditures on the State of current spending. I'm looking at the tab to calculate the properties of text field.  But I don't see a way to remove my two fields.

    Then, I set up a field that contains a negative, except when I display the field in the form, the negative is positive.  I enter-1 as a default value to my field of 'subtraction '.  I was then several 1 negative against most of payment the amount so I can get a negative on the amount of the payment.  I was then going to add the negative on the amount of the payment for the total amount to pay and arrive at a net due, but it does not work.

    Here is the calculation I'm doing:

    Total spending (field calculated from all previous fields.)

    Deductible expense (entered by the user)

    NET check fresh (Total expenses - deductible).

    Can someone tell me how to proceed?

    Thank you

    Dennis

    With Acrobat, there are 3 options of calculations.

    "The field is the _____ of the following fields:" options are for the sum, product, average, min and max operations or actions that could be repeated on several fields. We do generally not subtract or divide several fields in action.

    'Simplified field notation' uses only the field names and values. The field names must begin with an alphabetic character and has no spaces or special characters. Cannot perform conditional control statements or functions. Special characters or spaces may be in domain names, if the JavaScript escape character precedes the special character or a space. 4 arithmetic operations can be performed.

    'Calculation of custom JavaScript' has no restrictions on field names, control statements, functions or mathematical operations. We have access to the field object and the value property of the field object.

  • Addition/subtraction of TIMESTAMP interval

    Hi all

    I have a requirement to subtract the number of days or months or weeks of a Timestamp column and get a timestamp value in return.

    I have the following table-
    Table name: Test
    Columns:
    Effective_End_Date: TIMESTAMP
    Interval_type: VARCHAR2
    Interval_value: NUMBER

    In general, we'd go with the following query-

    Select Effective_End_Date - '1'-DAY interval of the test;

    The issue is I have to subtract the value stored in interval_value stored in the effective_end_date table. In addition, the type of interval (DAY, MONTH, etc.) is stored in the INTERVAL_TYPE.

    Does anyone could suggest any request for this? Let me know if you count more inputs.

    Thank you
    Maithily.

    Hello

    Sorry, my mistake. All branches of the CASE expression must return the same type of data. The version below works, because all branches return a TIMESTAMP:

    SELECT     test.*
    ,       CASE interval_type
                WHEN 'DAY'   THEN effective_end_date - NUMTODSINTERVAL (interval_value,     'DAY')
             WHEN 'WEEK'  THEN effective_end_date - NUMTODSINTERVAL (interval_value * 7, 'DAY')
             WHEN 'MONTH' THEN effective_end_date - NUMTOYMINTERVAL (interval_value,     'MONTH')
            END AS new_timestamp
    FROM      test;
    
  • In subtracting two stamps, and indicating the number of hours between them.

    Hello people,

    I have 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 added the columns as timestamp (0) since I have no need for decimals)

    Here's what I have:

    a table name: conc_test

    table information:

    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 AM 10.00.00

    the two table name: rls_break

    Info table two:

    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 columns, so it would be more readable to reading the forum, FYI)

    That's 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 '' appropriate Force. ''
    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 column 'Age' to display the total number of hours between (cyl_cast_time of the conc_test column) cast time and pause time (column break_d_t of rls_break)


    I thank the of for any help.
    ...
    extract(day from rls_break.break_d_t-conc_test.cyl_cast_time)*24
     + extract(hour from rls_break.break_d_t-conc_test.cyl_cast_time)
     + extract(minute from rls_break.break_d_t-conc_test.cyl_cast_time)/60
     + extract(second from rls_break.break_d_t-conc_test.cyl_cast_time)/(60*60) "Age",
    ....
    
  • calculate the difference between two timestamps

    Hello
    I'm new in PL/SQL and have the following problem. In our application, there are events that insert records into a table with a parameter "processing_date" of type DATE (when they will be processed). For a new type of events, I have to plan the 'processing_date' at 18:00 on the day of insertion, if the event has happened until 18:00 and sysdate if event occurs after 18:00.
    In a pseudo-code that will be
    IF to_char(SYSDATE,'HH24:MI:SS') > 17:59 min 59 s ' THEN - the event took place after 18:00
    processind_date: = sysdate;
    Else - the event has happened until 18:00
    processing_date: = current_timestamp + ('timestamp at 18:00 ' - current_timestamp); -> processing_date: = today at 18:00
    END IF;

    I'll appreciate any help.

    Thank you.

    dariusgeo wrote:
    processing_date: = current_timestamp + ('timestamp at 18:00 ' - current_timestamp); -> processing_date: = today at 18:00

    For 18:00 of the current date, you can do:

     processing_date := TRUNC(SYSDATE)+18/24;
    

    TRUNC will be truncates the current date ' 00:00:00 '.
    Add 18/24 means add 18 hours (1 day / 24 * 18).

    Kind regards.
    Al

    Published by: Alberto Faenza 22 may 2013 22:07

  • How to store the difference between two timestamps as a number?

    Hello
    I need to find the difference between 2 variables of timestamp and the result will be stored as a number in minutes?
    as
    declare
    timestamp (7) of the fir_timestamp: = 1 January 2012 13:30 ';
    timestamp (7) of the sec_timestamp: = 1 January 2012 14:00 ';
    c number;
    Start
    c:=((sec_timestamp-fir_timestamp)/(24*60));
    dbms_output.put_line (c);
    end;

    962813 wrote:
    declare

    -fir_timestamp timestamp (7): ='01 - jan - 2012 13:30 ';
    timestamp (7) of the sec_timestamp: = 1 January 2012 14:00 ';  Incorrect type declaration

    fir_timestamp timestamp: = 1st January 12 01.30.00.000000 PM';
    sec_timestamp timestamp: = 1st January 12 02.00.00.000000 PM';
    c number;
    Start
    c: = ABS ((extrait (HEURE de sec_timestamp) - extract (fir_timestamp TIME)) * 60) +.
    ABS ((extrait (MINUTE de sec_timestamp) - extract (fir_timestamp MINUTE)));
    dbms_output.put_line (' interval Min Total:-' | c);
    end;
    /
    declare
    *
    ERROR on line 1:
    ORA-01830: date format picture ends before converting all of the input string
    ORA-06512: at line 6

    Follow what Paul has done...

    In fact, you do not need timestamp, date data type is enough

    SQL> declare
      2     fir_timestamp date :=
      3        to_date('01-jan-2012 13:30:00','dd-mon-yyyy hh24:mi:ss');
      4     sec_timestamp date :=
      5        to_date('01-jan-2012 14:00:00','dd-mon-yyyy hh24:mi:ss');
      6     c number;
      7  begin
      8     c:= round((sec_timestamp-fir_timestamp)*24*60);
      9     dbms_output.put_line(c);
     10  end;
     11  /
    30
    
    PL/SQL procedure successfully completed.
    

    If you want to place on timestamp

    SQL> declare
      2     fir_timestamp timestamp :=
      3        to_timestamp('01-jan-2012 13:30:00','dd-mon-yyyy hh24:mi:ss');
      4     sec_timestamp timestamp :=
      5        to_timestamp('01-jan-2012 14:00:00','dd-mon-yyyy hh24:mi:ss');
      6     c number;
      7  begin
      8     c:= round((
      9     to_date(to_char(sec_timestamp,'ddmmyyyyhh24miss'),
     10             'ddmmyyyyhh24miss')-
     11          to_date(to_char(fir_timestamp,'ddmmyyyyhh24miss'),
     12             'ddmmyyyyhh24miss')
     13           )*24*60);
     14     dbms_output.put_line(c);
     15  end;
     16  /
    30
    
  • How to find the difference between the two timestamp columns

    Dear all,
    Please solve my problem,
    I have Table name of the folder that has the following columns,
    EmpID in the number column, timestamp dat
    who has the following values
    Expand | Select | Wrap | Line numbers
    EmpID dat
    ====== ====
    101 4/9/2012 09:48:54
    101 4/9/2012 09:36:28
    101 4/9/2012 18:16:28
    101 4/10 / 2012 09:33:48
    101 4/10 / 2012 12:36:28
    101 4/10 / 2012 20:36:12
    101 4/11 / 2012 09:36:28
    101 4/11 / 2012 16:36:22
    Here, I need to display the following columns

    EmpID, min (DAT) as start, max (dat) as end and difference (max (dat) - min (dat) for each day,
    for example,.
    End difference EmpID Strart
    101 4/9/2012 09:48:54 09/04/2012 18:16:28 8.28
    Like this.
    3 days different here is so it should return 3 discs with the mentioned columns above,
    Please help me find it.

    Thank you
    Kind regards
    Gurujothi

    Published by: Gurujothi on April 25, 2012 04:45

    Gurujothi wrote:
    Dear Alex,
    Thank you for your reply,
    Depending on whether you are your quesy showing it in hour and minutes format its right but you mention all rows of the query
    If the table has more than 3000 lines then how it is possible to write this much higher request,
    my table with almost 3500 lines.

    You can make a few changes in the above query I posted the last I mentioned?

    Thank you.

    Published by: Gurujothi on April 25, 2012 23:18

    Hello

    You don't need to write whole records 3000 it... alex just wrote that for example have no table as your table...
    so just use the under part of this query as in the previous post, alex:

    select empid, trunc(dat),
           min(dat) as start_dat,  to_char(min(dat), 'hh24:mi:ss') as start_dat_part,
           max(dat) as end_dat, to_char(max(dat), 'hh24:mi:ss') as end_dat_part,
           max(dat)-min(dat) diff, to_char(max(dat)-min(dat), 'hh24:mi:ss') diff_part,
           extract(day from max(dat)-min(dat)) || ' days'
           || ':' ||  extract(hour from max(dat)-min(dat)) || ' hours'
           || ':' ||  extract(minute from max(dat)-min(dat)) || ' mins'
           || ':' ||  extract(second from max(dat)-min(dat)) || ' sekas'
    from trans
    group by empid, trunc(dat)
    

    hope this fixes your need

  • Subtract two selections?

    http://i.minus.com/jbslkoD73SReDJ.jpg

    I have the saved selection, I want to load another selection at the breast while subtracting? I've tried Boolean methods, I searched textbooks, same AdobeTV for an answer, I know it's possible and I'm having a brain Peter

    I saved 1 selection and then make a new selection 2 and saved. With no active selection I went to the palette layers and Ctrl + click selection 1 the keys Alt + Ctrl + click on selection 2. What you want.

    Change the results fill in:

  • Subtracting two fields and button

    I'm trying to subtract text Text11 11.1 and there total, Text11.2, I tried different from Java and FromCals. Help, please!

    Also is it possible to add a button that is bound to the pencil tool on a form?

    Hmmm. try to remove value formatting in the Time2Num function option.

    var Interval = Time2Num (StopTask) - Time2Num (StartTask)

    Steve

Maybe you are looking for

  • kuklorest

    Hello, a year ago I had Kuklorest on my MacBook Pro and was able to remedy.  Tonight I used Chrome and put a pop up warning that I had Tapsnake.  I HAVE NO IDEA WHAT CAME OVER ME, BUT I CLICKED IT!  I am so embarrassed.  In any case, I knew immediate

  • New Ipod Touch does not illuminate

    Buy IPod Touch last summer (August 2015) and died this morning. Can not activate it or it will load. Any suggestions?

  • 9.3.1 iOS used to install on the iPhone 6

    I tried several times to install the new ios and it won't work.  It downloads the update well and then goes through the installation process but comes back with an error: "cannot install update.» Year error occurred installing iOS 9.3.1. "" Try again

  • Problem with the BIOS boot image

    Hi - I recently updated day/flashed the BIOS of my T60 (2623-KFU) through windows by using the Setup files in the support section. I noticed the image of the characteristic changing BIOS boot and creates the Logo.Mod file that I have included in my B

  • Long list of files in square brackets, such as: {859fd135-7f2e-417d-9843-512b4cff43f7}

    My C drive has a few dozen of these files listed before all of my subfolders brackets. What are they and are they required to keep? Thank you SSG978 ssg978