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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️