Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oracle systimestamp (sysdate) to milliseconds

Could you provide implementation of stored function to get current systimestamp as milliseconds.
Something I can use like

select current_time_ms from dual;

and get the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.

Thanks.

like image 644
Mike Avatar asked Aug 22 '11 13:08

Mike


People also ask

Does Oracle date store milliseconds?

Answers. Dates do not contain milliseconds, they only go as fine as seconds. You might want to try a timestamp datatype.

What is the difference between Sysdate and Systimestamp?

SYSDATE: Show the date and time of the database server. CURRENT_DATE: Show the date and time of the session timezone. SYSTIMESTAMP: Shows the date and time of the database server, in a TIMESTAMP WITH TIME ZONE data type.

How do I convert Sysdate?

select TO_CHAR(to_date('01-JAN-2013', 'DD-MON-YYYY'), 'DAY') FROM DUAL; answer was :TUESDAY. select TO_CHAR(to_date(sysdate+1, 'DD-MON-YYYY'), 'DAY') FROM DUAL; answer is :MONDAY.

What is the difference between current timestamp and Systimestamp?

SYSTIMESTAMP returns current timestamp on database server, while current_timestamp returns current timestamp on client machine. So if your database server is in New York and client box is in California, SYSTIMESTAMP will be 3 hours ahead of CURRENT_TIMESTAMP.


1 Answers

  • DB timezone agnostic
  • with milliseconds
  • works in XE
    function current_time_ms
        return number
    is
        out_result number;
    begin
        select extract(day from(sys_extract_utc(systimestamp) - to_timestamp('1970-01-01', 'YYYY-MM-DD'))) * 86400000 
            + to_number(to_char(sys_extract_utc(systimestamp), 'SSSSSFF3'))
        into out_result
        from dual;
        return out_result;
    end current_time_ms;
like image 91
Mike Avatar answered Sep 20 '22 11:09

Mike