0

Is there a quick way to get the exact same result when using date.now() method (returns milliseconds that elapsed since 1970-01-01) in JS via SQL select statement?

I guess this could be the start:

select current_timestamp from dual;

...but from that point on, I got stuck with getting the format as mentioned above.

Phil Gee
  • 33
  • 7
  • Does this answer your question? [How to get millis of timestamp since 1970 UTC in Oracle SQL?](https://stackoverflow.com/questions/31652232/how-to-get-millis-of-timestamp-since-1970-utc-in-oracle-sql) – astentx Aug 16 '21 at 13:34

1 Answers1

0

That would be

SQL> SELECT     (CAST (SYSTIMESTAMP AS DATE) - DATE '1970-01-01')
  2           * 24
  3           * 60
  4           * 60
  5           * 1000
  6         + MOD (EXTRACT (SECOND FROM SYSTIMESTAMP), 1) * 1000 result
  7    FROM DUAL;

          RESULT
----------------
   1629124489718

SQL>
Littlefoot
  • 131,892
  • 15
  • 35
  • 57
  • @PhilGee - I don't think this is correct. JS `date.now()` returns milliseconds since 1 January 1970 UTC. `SYSTIMESTAMP` is the timestamp in the time zone of the database server, which may be different from UTC. Use `systimestamp at time zone 'UTC'` instead. –  Aug 16 '21 at 13:41
  • @mathguy - Oh, yes - that's right. A fact one shouldn't forget about... like I did ;-) Thank you! – Phil Gee Aug 17 '21 at 12:08