Difference between 2 timestamps in seconds

Can someone tell me how to subtract 2 timestamps and
get the difference in seconds? does not "rip."
He always gives a value between 0 and 59, I want total
seconds, not the seconds part of the interval.

I use Oracle Database 10 g Express Edition Release 10.2.0.1.0
SQL> @id8
SQL> drop   table holder ;

Table dropped.

SQL> create table holder (
  2  beg_date timestamp,
  3  end_date timestamp)
  4  /

Table created.

SQL> INSERT INTO HOLDER VALUES(to_timestamp('2009-07-16:19:00:01.50','YYYY-MM-DD:HH24:MI:SS.FF'),
  2                        to_timestamp('2009-08-17:20:00','YYYY-MM-DD:HH24:MI'));

1 row created.

SQL> COMMIT;

Commit complete.

SQL> SELECT EXTRACT (DAY    FROM (END_DATE-BEG_DATE))*24*60*60+
  2           EXTRACT (HOUR   FROM (END_DATE-BEG_DATE))*60*60+
  3           EXTRACT (MINUTE FROM (END_DATE-BEG_DATE))*60+
  4           EXTRACT (SECOND FROM (END_DATE-BEG_DATE)) DELTA
  5  from holder
  6  /

     DELTA
----------
 2768398.5

Tags: Database

Similar Questions

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

  • 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
    
  • Difference between 2 timestamps

    I don't know why my results give me 0. I'm doing a simple date difference. Here is my code:

    < cfset nowtime = now() >

    < cfif DateDiff ("s", getpost.dtstamp, nowtime) lt 60 >

    < cfset subsist = DateDiff ("s", getpost.dtstamp, nowtime) & "seconds ago" >

    < cfelseif DateDiff ("m", getpost.dtstamp, nowtime) lt 60 >

    < cfset subsist = DateDiff ("m", getpost.dtstamp, nowtime) & "minutes ago" >

    < cfelseif DateDiff ('h', getpost.dtstamp, nowtime) lte 23 >

    < cfset subsist = DateDiff ("h", getpost.dtstamp, nowtime) & "hours" >

    < cfelseif DateDiff ("d", v.dtstamp, nowtime) lte 7 >

    < cfset subsist = DateDiff ("d", getpost.dtstamp, nowtime) & "days" >

    < cfelse >

    < cfset subsist = dateformat (getpost.dtstamp, "mmmm dd") >

    < / cfif >

    When I view the original variables, it says:

    getPost.dtstamp = 2012-03-10 17:33:25.0 I do not know whence cette.0 because the database does not show that.

    now = {ts ' 2012-03-12 16:16:02 '}

    I get 0.

    Well, that explains it. You have the wrong unit of DateDiff.  "m" means for months, not minutes.

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

  • 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

  • Difference between bookmarks per Page and the anchor icons

    Hello

    I use InDesign each year to update a large guide.  I had sort of teach me how to use this software, but since I don't use not all year, I forgot things.  One of them has to do with my favorites.  I noticed that all my favorites have an icon of the page, but it has an icon of the anchor, like this:

    indesign1.JPG

    First of all, what is the difference between them?   And second, every time I update the Table of contents, anchor moves where I nested it all the way to the top of the bookmarks, right under the Table of contents, as follows:

    indesign2.JPG

    Anyone know why this is happening?  I think it has to do with the fact that this particular section is not explicitly listed in the Table of contents, but I don't want to have a bookmark for it.  But I would like to embed the bookmark in the right position, what is shown in the first image in this post.  Could someone help me this?  Thank you!

    I think that I thought about it.  First of all, most of the bookmarks have was probably generated by the table of contents itself.

    In terms of changing a bookmark of anchor text to a bookmark of the page, I realized that I had to get out the block of text, simply use the selection on the page and then create a new bookmark.

    So I did, and now all of my icons are pages in the bookmarks bar.  However, whenever I update the table of contents, he always puts this bookmark immediately under the table of contents.  I think this behavior is because this particular bookmark (called sweeps Dates) is not actually included in the table of contents (by design).  I have it in a different style to make the table of contents is not picking it up.  But I guess since the table of contents generates all the other favourites, it sorts the update and then put just created this maually bookmark "Balaie les Dates" below, above the rest of the bookmarks.

    If there is a case, I don't know if there is a work around specific to this situation.  It could be one of these minor idiosyncrasies that I'll have to deal with.  It is not a big problem to have to move whenever I update the table of contents, and I mostly just try to improve my understanding of InDesign in asking about this behavior.

  • Second difference between dates GMT?

    Hello

    I need to get the second difference between a date later GMT and current date of GMT.

    My code looks like this:

    Calendar futureDate = Calendar.getInstance(TimeZone.getTimeZone("GMT"));futureDate.set(Calendar.YEAR, 2009);futureDate.set(Calendar.MONTH, 11);futureDate.set(Calendar.DATE, 12)futureDate.set(Calendar.HOUR, 10)futureDate.set(Calendar.MINUTE, 43)futureDate.set(Calendar.SECOND, 18);
    
    int secs = (futureDate.getTime().getTime() - System.currentTimeMillis()) / 1000;
    

    This code gives me 12 hours too many seconds. I'm I have GMT + 7 time zone. DateTime, the value source Blackberry.

    When I debug, and print the futureDate, it shows me my timezone instead of GMT.

    Another weird thing. If I subtract the TimeZone.getDefault () .getRawOffset () in my calculation of seconds, the seconds are then 7 hours in advance. Where are these 5 hours from extra?

    Thank you.

    Sorry, just a little chip, I don't have the time to carefully review your problem (maybe do later) but two things:

    (1) System.currentTimeMillis () returns the time UTC.  I think that CMJ is incorrect when he says that it returns local time.

    (2) GMT is NOT necessarily UTC time on the device.  GMT in London at the present time is UTC to 1, because we (I'm in the United Kingdom) use Daylight Saving.  If you want to discover the real hour GMT, on the device or the Simulator, set time GMT from Casablanca.

    I need to check these, do not have the time, but here are some other thoughts on the top of my head.

    (a) timezone "GMT" is, in fact, Casablanca GMT, i.e. not affected by Daylight Saving.

    (b) Note When you specify the time of the calendar, there are two forms of time:
    TIME - what you used, can be morning or afternoon

    HOUR_OF_DAY - which I think is what you should use.

    So change your code to use HOUR_OF_DAY, and I suspect that this could work.  But as noted, just off the top of my head...

  • Difference between ' Please read physical Total i/o per second "and"physical IO read queries per second.

    What is the difference between "Physics read Total IO requests by s ' and ' physical IO read requests per s ' metric in dba_hist_sysmetric_summary?

    Documentation (reference, Descriptions of statistics):

    IO physical read requests : number of read requests for application activity (mainly the buffer cache and direct load operation) that read one or more blocks of data by request. It is a subset of statistics 'physical read IO total number of applications.

    requests for IO total physical reading : number of read requests that read one or more blocks of data base for any activity, including the application instance, backup and restore, and other public services.

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

  • What is the difference between the cookies keep until I close firefox and the history of cookie empty closing firefox?

    In the settings of Firefox 33.0 (I use Ubuntu 14.04, but the functionality is the same for Windows 7) there are two ways to delete cookies when firefox closes. Or at least, there seems to be.

    Is first the cookies keep until firefox is closed

    Second is to check the box for clear history of firefox closing and in the settings check cookies.

    What is the difference between these two options?

    I usually have two configuration but I noticed that a connection was not save for td canada trust EasyWeb, even though I have an exception set for it. Now I unchecked to remove cookies by disabling the history on close and connection records correctly.

    This connection allows to save 7 cookes under easyweb.td.com and 10 cookies under td.com and I have exceptions defined for both. If I clear the history when closing and include cookies, half of the td.com cookies disappeared when I close firefox and re - open. The same is true if I'm not the exception.

    So currently I can't find a way to keep all cookies if I clear the cookie history when firefox closes. What is the difference with this option?

    When you change the default cookie 'to life' of "keep until: they expire" to "keep until the: I close Firefox", Firefox changes all persistent cookies that sites set session cookies. To allow a site to place a persistent cookie, you need to make an exception (site permission).

    When you turn on the story to stop compensation and include cookies, running a completely separate process that doesn't doesn't pay attention to the duration of cookie or exceptions (permissions site). There just nukes all.

    Note that some cookies could survive if they are encoded in the history file of your session of compensation at the stop, a Firefox uses to restore your tabs and windows from last session. I have not tested.

  • Hi, I can not find the cuda switch in my PowerMac dual g4 in the opposite direction, what is the difference between reset pram by touch or cuda?

    Hello

    I can't find the switch cuda in my PowerMac g4 dual mirrored, 1.00

    What is the difference between reset pram by touch or cuda?

    Switching on the open Mac I can see a small red light and I listen to the classic sound

    but nothing on the monitor.

    FireWire connection with my mac Mini, I can view and save the hd PowerMac

    The battery was completed in December 2012 (it's weird, cause I bought the double

    years before and never changed)

    Thanks for your attention and sorry for my English...

    First of all, I have to warn. G4 MDD don't have a CUDA button and old Macs - it has a PMU reset button. The difference is that, for a computer with the PMU system like yours, you give the key ONLY a short thrust, not longer than a second.

    If treat you it as if it was a CUDA button and hold for 20 seconds, you will seriously damage your computer. That said, this image shows the location of the PMU reset in a G4 MDD:

    What is the difference between reset pram by keyboard or cuda?

    Since your G4 has no CUDA reset ability, this becomes a moot point. In the old Mac (G3 Beige and more - the "Old world ROM" Macs) reset PRAM via the keyboard is not completely zero everything; the CUDA reset did.

  • Satellite A135: Difference between recovery options

    Hello

    I have a Toshiba Satellite A135, OS: Vista Home.

    I'm trying to reformat my laptop using the supplied with my laptop system recovery disk.
    I gives me two options when I run the disc:

    (1) restoration of out-of-box factory State, and
    (2) wipe the hard drive.

    What are the differences between these two options?
    My goal is to make a total of cleaning on my HARD drive to get rid of malware.

    It's a mobile US and so I not quite sure what the exact difference could be m but as I m not wrong the first recovery option set laptop back to the factory settings.
    Another, the second option would be to format the HARD drive only

    If you have tried both options thanks to post the results

    Welcome them

  • What is the difference between the Satellite A300-1EC & Satellite A300-1EG

    Why does the Satellite A300-1EC more expensive stand as Satellite A300-1EG, but configuration loses him?

    What is their substantial distinction in?
    What model of laptop may indicate, in this price range?

    Hello

    Satellite A300-1EC belongs to the Group PSAG0E and Satellite A300-1EC to PSAG4E. When this model numbers are different, it means that they do not have the same hardware configuration.

    The first has Intel graphics controller 965GM (Crestline). The second is M82XT ATI (256 MB). The capacity of the HARD disk is not the same. The first a 160 GB HDD and secondly a 250 GB.

    So that's the difference between these notebooks of the A300.

    In my view, the other is better. You have to make your decision and choose the right one.

  • What is the difference between folders: ' all ' and 'Photos' - it's just to start!

    Following a major problem with iPhoto and several telephone conversations with Apple, they have updated my OS to OS X El Capitan 10.11.2 which of course includes Photos.  Considering that it took a few minutes to import, for example, 400 photos from a trip to New Zealand, it now takes 40 minutes to import and sort then maybe a dozen. I seem to end up with copies in records last import, all pictures and Photos.  Also following the upgrade, all my previously deleted photos "reappear" so I got over 18 000 instead of the expected 12-13, 00.  It took hours to sort - and still sorting...

    First question: what is the difference between all the Photos (posted at random), Photos (posted by year/day)?

    Second: Photos sitting in the last import files - where do they go once they have been placed in my Albums?

    1. they are not records - photos exactly as the iPhoto files hold not photos - they have other folders or albums

    2 - both are standard SystemTop - photo albums, photo exhibition which is not hidden in a sort of photo date (years/collections/moments) and all photos shows all pictures sorted by date of adding Photos

    3 - the last import also isn't a folder - it's a special album that shows the latest photos imported - they will not anywhere – when you import again the importation of latest news is shown

    4. don't 'put' Photos in albums and they don't go anywhere that you never move anything in Photos (or iPhoto) - all photos are still in the library and view you through different methods, including albums (used for the Organization), all pictures, Photos and possibly other SystemTop albums

    LN

Maybe you are looking for