Give Me The Current Date Please

Did you know that in addition to SYSDATE, there is also a SQL function called CURRENT_DATE? Basically, they are the same except one important difference.

SYSDATE returns the current date and time set for the operating system on which the database resides whereas CURRENT_DATE returns the current date in the session time zone.

Here is a quick example to illustrate that difference:

SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'MM/DD/YYYY HH:MI:SS'
  2  /

Session altered.

SQL> SELECT SYSDATE, CURRENT_DATE
  2    FROM DUAL
  3  /

SYSDATE             CURRENT_DATE
------------------- -------------------
04/17/2008 04:09:56 04/17/2008 04:09:57

SQL> ALTER SESSION SET TIME_ZONE = 'EST'
  2  /

Session altered.

SQL> SELECT SYSDATE, CURRENT_DATE
  2    FROM DUAL
  3  /

SYSDATE             CURRENT_DATE
------------------- -------------------
04/17/2008 04:09:56 04/17/2008 07:09:57 

Of course, I’m not telling you anything new here, it’s all in the documentation :)


Possibly related:


Tagged | Post a Comment | Trackback URI