Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get system date and time in oracle sql?

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?

like image 282
sohaib sonu Avatar asked Oct 17 '25 03:10

sohaib sonu


1 Answers

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

like image 133
MT0 Avatar answered Oct 18 '25 17:10

MT0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!