DEV Community

Cover image for Get the current unix timestamp in oracle
Adrian Matei for Codever

Posted on • Edited on • Originally published at codever.dev

3 1

Get the current unix timestamp in oracle

The following expression returns the Unix time in milliseconds independent of the time zone.

It sums the number of days passed from the start of the Unix epoch multiplied by the number of milliseconds in a day (24 * 60 * 60 * 1000 = 86400000) plus number of milliseconds past midnight (SSSSS with a precision of 3 FF3 to express milliseconds).

It uses the SYS_EXTRACT_UTC method to extract the UTC (Coordinated Universal Time—formerly Greenwich Mean Time) from the current timestamp (systimestamp in oracle):

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'))
  FROM dual;
Enter fullscreen mode Exit fullscreen mode


Reference -
https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/SYS_EXTRACT_UTC.html


Shared with love from Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Image of Datadog

Measure and Advance Your DevSecOps Maturity

In this white paper, we lay out a DevSecOps maturity model based on our experience helping thousands of organizations advance their DevSecOps practices. Learn the key competencies and practices across four distinct levels of maturity.

Get The White Paper

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up