3

I am using oracle apex when ever I try the code

SELECT TO_CHAR (SYSTIMESTAMP) "NOW" FROM DUAL

The result is always behind 5 hours. Can any one help me for this query?

Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31
sohaib sonu
  • 41
  • 1
  • 3
  • Are you looking for the time on the database server? The client? Something else? What time zone is the database server using? What time zone do you want the result in? – Justin Cave Oct 30 '21 at 09:32
  • Try [systimestamp at local](https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Datetime-Expressions.html) or [current_timestamp](https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/CURRENT_TIMESTAMP.html). (I would write this as an answer but I don't have Apex to test with.) – William Robertson Oct 30 '21 at 09:53

1 Answers1

5

To get the time on the database server:

SELECT SYSTIMESTAMP FROM DUAL

Or, if you want to format it as a string:

SELECT TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM')
FROM   DUAL;

If you want the time on the client then:

SELECT CURRENT_TIMESTAMP FROM DUAL;

or, you can take the system time and convert it to local time:

SELECT SYSTIMESTAMP AT LOCAL FROM DUAL;

(Or you can format either as a string by wrapping it in TO_CHAR)


Note: when you state "The result is always behind 5 hours", you need to make sure you also compare time zones.

db<>fiddle here

MT0
  • 143,790
  • 11
  • 59
  • 117