Calculate the difference of date in milliseconds

Hi all

Version:-Oracle Database 10 g Enterprise Edition release 10.2.0.3.0

Requirement:-to calculate the difference between current systimestamp and January 1, 1970 with milliseconds up to precision (we need this to store in other tables)

The query I gave below it gives a value of up to 1 sec accuracy

Select (sysdate - to_date (January 1, 1970 00:00:00 ',' DD-MON-YYYY HH24;)) SS')) * (24 * 60 * 60 * 1000) double;

Output
1261545437000

After 1 second
1261545439000 and so on

I can the difference in accuracy to the millisecond
select (sysdate - to_date('01-JAN-1970','DD-MON-YYYY')) * (24 * 60 * 60 * 1000)+to_number(to_char(systimestamp,'FF3')) from dual;

Max

Published by: Massimo Ruocchio on December 23, 2009 12:19
Fix

Tags: Database

Similar Questions

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

    Hello

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

    Records of the time table example:

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

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

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

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

    Thanks in advance.

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

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

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

    SQL >

    SY.

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

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

    Try the below formula.

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

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

    Thank you!

  • Calculate the difference in days between two Dates

    Hello

    I'm trying to understand how to calculate the difference in days between two dates using JavaScript in LiveCycle. (Minimum = JavaScript knowledge)

    Where 'Start_Date' and 'Current_Date' are the names of the two dates in the palette of the hierarchy. (the two Date/time field)

    * Current date is using the object > value > execution property > current Date/time

    I need a text or number field showing the difference in days. (Difference_in_Days)

    I noticed the following code is pretty standard among other responses:

    var

    Start_date = new Date (Start_Date);

    var

    Current_Date = new Date (Current_Date);

    var

    nAgeMilliseconds = Current_Date.getTime) - Start_date.getTime ();

    var

    nMilliSecondsPerYear = 365 * 24 * 60 * 60 * 1000 ;

    I know there is lack of code and code above are may not be not correct.

    Please notify.

    OK, that's because of the way that javascript and works of the calculate event.  The field will be filled with whatever the script resolves at the end of execution. Technically, your script does not have a value because the last thing you do is an assignment to a variable.  Change the last line as follows:

    Math.ABS ((firstDate.getTime)

    ((- secondDate.getTime (()) / (oneDay));

    (eliminate the variable assignment) and get rid of the app.alert.  Your script will "return" (have) regardless of the value of calculation from the East and which will be stored in the field.

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

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

    Cell B2 - 08:00

    Cell C2 - 10:50

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

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

    Thank you

    Hi sapirs,

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

    Formula in D2 (fill down)

    = C2−B2

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

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

    What Data Format have your result cells?

    Kind regards

    Ian.

  • How to calculate the difference in lines

    Hi, the case is:

    Column1 Column2 Column3 column4

    C114 00301152 20/07/2010?

    C114 00301152 10/20/2009?

    C114 00301152 16/06/2009?

    I want to calculate the difference of Column3 in 1st place with the second row and second row to the third row column4 unlike

    Thank you very much

    Luca

    Hi, Luca,

    user12880276 wrote:

    Hi, the case is:

    Column1 Column2 Column3 column4

    C114 00301152 20/07/2010?

    C114 00301152 10/20/2009?

    C114 00301152 16/06/2009?

    I want to calculate the difference of Column3 in 1st place with the second row and second row to the third row column4 unlike

    Thank you very much

    Luca

    You can use the analytical function of LAG (or LEAD).

    For example, if Column3 is a DATE:

    SELECT column1, Column2, Column3

    , Column3 - (Column3) in ADVANCE ON (ORDER BY Column3) AS days_diff

    FROM table_x

    ORDER BY DESC - optionally Column3

    ;

    If you would care to post CREATE TABLE and INSERT instructions for the sample data, and then I could test this.

    Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?

    Column1 and column2 play no role in this problem (except that appear in the output)?  If so, you will need to PARTITION BY in the analytical clause.

  • Calculate the difference between the subtotals

    I'm working on a simple report that looks like this:

    EmployeeID EmployeeName Date salary wages
    1234 Tom June 1, 2009 $2000.00
    2345 harry $2400,00 June 1, 2009
    3456 sally $3000.00 June 4, 2009
    Partial total salary: $7400,00

    Advances of salary Date EmployeeID EmployeeName
    2345 harry $1000.00 may 15, 2009
    3456 sally $750.00 may 15, 2009
    Advances subtotal: $1750,00
    Total: $5650,00

    Is there any function in Discoverer, which calculates the difference between subtotals and the poster as a total. Please advise if you can create a named for this sum calculation?

    Published by: user1049091 on August 6, 2009 11:33

    Published by: user1049091 on August 6, 2009 12:38

    Hello

    Not really possible. You the best approach is probably to create a named calculation that contains the difference: for example

    Decode (salary_type, 'Pay', 'Progress', - wages)

    Then create a total on this calculation. You can often hide the calculation itself in terms of formatting and white text on white background.

    Rod West

  • Need help to calculate the difference between times

    Hi all

    I have two fields that stores just the hour in 24-hour ex: 08:00 and 20:00 now I want to calculate the difference between two times

    Kindle help me

    Thanks for your help

    Thank you
    Ravi

    Hello

    diiference in hours

    SQL> WITH T AS (SELECT '08:00' ST_TIME, '20:00' END_TIME FROM DUAL)
      2  SELECT (TO_DATE (END_TIME, 'HH24:MI') - TO_DATE (ST_TIME, 'HH24:MI')) * 24 DIFF_HOURS
      3    FROM T;
    
    DIFF_HOURS
    ----------
            12
    
    SQL> 
    

    G.

  • FormCalc - how to calculate the difference between the two fields datetime in hh: mm?

    Hello!

    I am building a form of time sheet in which I need to calculate the difference between the start and end times and present the result.

    I'm trying to do with FormCalc but if it is easier with JS is ok too.

    So that's what I did on the total field, by using the calculate on a NUMERIC field called decimalValue event:

    elapsed = Time2Num (endTime.formattedValue, "HH: mm")-Time2Num (startTime.formattedValue, "HH: mm")

    And then I tried to convert a time field:

    Total = decimalValue.rawValue;

    $.formattedValue = Num2Time (total, "HH: mm")

    Well, it doesn't work, it gives me crazy results in the datetime (total) field. If I type 09:00 and 09:30, the final result is... 22:30. Huh?

    Please, could someone help me understand how this thing works?

    Thanks a lot for the tips!

    Marcos

    Hi Marcos,

    Here are some examples:

    https://Acrobat.com/#d=kCPIgVkd09qrx6h-WRXxbQ

    https://Acrobat.com/#d=EsWqBMBt3sgEXnMSsK5pRA

    Hope that helps,

    Niall

  • How to find the difference in date in years, months and days

    Hello
    I need to find the difference between 2 dates in the following way "years months days". "
    Please can help me, how can I achieve this.

    for example, in the scott schema emp table, I need to find the difference in date between sysdate and hiredate for an employee in the following way.

    12 years 7 months 4 days.

    Hello

    Please, see this post to AskTom [difference between 2 dates | http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:96012348060]. There is good information in this forum, for example you can also see this thread [calculation of years, months & days | http://forums.oracle.com/forums/thread.jspa?messageID=3115216�]

    Kind regards

    Published by: Walter Fernández on November 30, 2008 08:58 - adding another link

  • calculate the difference of unique column values

    I tried the info and the website to learn how to perform a "calculation difference" function on a single column (channel) of data.  For example if my data channel is a period of time to say the following: 100, 101, 99, 102, 100, 99...  I would like to calculate 100-101 101 - 99 then then 99-102 and so on for all the values.  How can I do this?

    Hi ranger,

    Looks like you're looking for the standard function "Calculate the disparity" ANALYSIS > basic math.

    Hope this helps,
    Ralf

  • Average of the difference in date in minutes

    Hi friends

    I have a table called attendance with 3 columns
    eid  number
    in   date
    out  date 
    two columns (in, out) of date are stored with date and time. The table will have multiple entries
    Is it possible that I can calculate the average of the difference in minutes between in and out of all the records
    using a single query or don't we have the right to use the loop.
    For Example
    
    eid         in                      out             difference in minutes
    1    01-01-2012 09:00:00   01-01-2012 10:00:00              60
    2    01-01-2012 09:05:00   01-01-2012 10:10:00              65  
    3    01-01-2012 09:10:00   01-01-2012 10:20:00              80  
    The result should be the average difference of minutes IE (60 + 65 + 80) / 3 which would be 68.33

    Thanks in advance
    Concerning
    Park

    Hello

    Use

    select avg((out - in) * 24 * 60)
    from 
    
  • calculate the difference in last hour?

    Hi all

    I have a sql like query below...

    SELECT sn.snap_time, st.value
    OF PERFSTAT. STATS$ SYSSTAT st, PERFSTAT. STATS$ SNAPSHOT sn
    WHERE st.snap_id = sn.snap_id
    and st.NAME = "user request".
    and sn.snap_time > to_date (March 1, 2011 10:00 ',' mm/dd/yyyy hh24:ss:mi "")
    order by 1 desc

    and output is inferior to...

    SNAP_TIME VALUE
    -------------------- ----------
    DECEMBER 19, 11 08:0:00 123501120
    19 DECEMBER 11 07:0:00 121336929
    DECEMBER 19, 11 06:0:01 119910473
    DECEMBER 19, 11 05:0:01 118900726
    DECEMBER 19, 11 04:0:07 118244503
    DECEMBER 19, 11 03:0:01 117202971
    DECEMBER 19, 11 02:0:01 115791474
    DECEMBER 19, 11 01:0:03 114008304
    19 DECEMBER 11 00:0:02 111347506
    18 DEC 11 23:0:01 108291559
    DECEMBER 18, 11 22:0:02 104340139
    18 DEC 11 21:0:01 99255636
    18 DEC 11 20:0:02 92775319
    DECEMBER 18, 11 19:0:01 85262323
    DECEMBER 18, 11 18:0:01 76262794
    DECEMBER 18, 11 17:0:01 68381704
    DECEMBER 18, 11 16:0:01 60100822
    DECEMBER 18, 11 15:0:01 51855773
    18 DEC 11 14:43733973 0:01
    DECEMBER 18, 11 13:0:01 35903397
    DECEMBER 18, 11 12:0:01 28494465
    18 DECEMBER 11 11:0:01 21724443
    DECEMBER 18, 11 10:0:02 15667617
    DECEMBER 18, 11 09:0:01 10526163
    DECEMBER 18, 11 08:0:01 6741565
    18 DECEMBER 11 07:0:00 3622640
    DECEMBER 18, 11 06:0:01 1623214
    DECEMBER 18, 11 05:0:03 207054

    But how can I write my query in a way if I can get the real value/difference of time before
    .. all the above value is cumulative and I want to calculate the value of the actual hours... lets say from
    DECEMBER 18, 11 05:0:03...

    He hopes to make sense... I'm on 9.2.0.5

    Hello

    To show the difference from the previous row (where "previous" is based on snap_time, ASCendcing order):

    SELECT    sn.snap_time
    ,        st.value
    ,       st.value - LAG (st.value) OVER (ORDER BY snap_time)     AS value_change
    FROM        PERFSTAT.STATS$SYSSTAT     st
    ,        PERFSTAT.STATS$SNAPSHOT     sn
    WHERE        st.snap_id     = sn.snap_id
    AND       st.NAME     = 'user calls'
    AND       sn.snap_time     > TO_DATE ( '03/01/2011 10:00:00'
                              , 'mm/dd/yyyy hh24:ss:mi'
                          )
    ORDER BY  snap_time     DESC
    ;
    

    In yopur sample data, it seems that each row is about an hour from its neighbours. If you missed an hour, or if you sometimes had two (or more) line in the same time, what wouold results you want? Post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all the tables and also post the results desired from these data.

  • How to calculate the difference in response times

    Hello
    I need to calculate the time difference of BI answers and I don't have access to the repository. I have the data in the following format

    2005-10-12 19:24:19 12/10/2005 19:32:04
    2005-10-12 19:50:47 2005-10-12 20:52:36
    2005-10-12 19:54:23 04/11/2005 22:47:32
    2005-10-12 21:05:51 12/10/2005 21:08:58
    2005-10-12 21:07:42 12/10/2005 21:14:47
    2005-10-12 21:09:02 12/10/2005 21:10:57
    I need to get the hours of elapased between these two columns. Please help me

    Thank you

    TimeStampDiff (SQL_TSI_HOUR, table.column1, table.column2)

  • Create lines based on the difference in date

    Hello

    I would like to create lines based on the difference between the start and end dates (per year).

    for example

    ID1  Start_time                                             End_time                                                      ID2
    07/01/2003 1, 12.00.00.000000000 2005-01-07 12.00.00.000000000 123

    07/01/1999 1, 12.00.00.000000000 07/01/2003 12.00.00.000000000 345

    I need:

    ID1  Start_time                                             End_time                                                      ID2
    07/01/2004 1, 12.00.00.000000000 2005-01-07 12.00.00.000000000 123

    07/01/2003 1 12.00.00.000000000 07/01/2004 12.00.00.000000000 123

    1 01/07/2002 12.00.00.000000000 07/01/2003 12.00.00.000000000 345

    07/01/2001 1, 12.00.00.000000000 01/07/2002 12.00.00.000000000 345

    07/01/2000 1, 12.00.00.000000000 01/07/2001 12.00.00.000000000 345

    07/01/1999 1, 12.00.00.000000000 07/01/2000 12.00.00.000000000 345

    Thank you

    Hello

    Here's one way:

    SELECT ID1

    , ADD_MONTHS (start_time, 12 * (LEVEL - 1)) AS start_time value

    , ADD_MONTHS (start_time, 12 * LEVEL) AS end_time

    id2

    FROM table_x

    CONNECT BY LEVEL<= months_between="" (end_time,="" start_time)="">

    AND PRIOR id2 = id2

    AND PRIOR SYS_GUID () IS NOT NULL

    ;

    I'm assuming that id2 is unique.

    Would what results you if end_time wasn't exactly N years after start_time?

Maybe you are looking for