w3resource

Oracle LOCALTIMESTAMP function

How to get current date and time values in the current session in Oracle?

The LOCALTIMESTAMP() function returns the current date and time in the session time zone in a value of datatype TIMESTAMP.

Syntax:

LOCALTIMESTAMP [ (timestamp_precision) ]

Parameters

Name Description
timestamp_precision (optional) Specifies the fractional second precision of the time value returned.

Note: LOCALTIMESTAMP returns a TIMESTAMP value while CURRENT_TIMESTAMP returns a TIMESTAMP WITH TIME ZONE value.

Pictorial Presentation

Pictorial Presentation of Oracle LOCALTIMESTAMP function

Examples: Oracle LOCALTIMESTAMP () function

The following statements shows the difference between LOCALTIMESTAMP and CURRENT_TIMESTAMP:

SQL> ALTER SESSION SET TIME_ZONE = '-2:00';
Session altered.
SQL> SELECT CURRENT_TIMESTAMP, LOCALTIMESTAMP FROM DUAL;

Sample Output:

  CURRENT_TIMESTAMP                      LOCALTIMESTAMP
  ---------------------------------------------------------------------------
  01-MAY-15 05.32.24.211000 AM -02:00    01-MAY-15 05.32.24.211000 AM
SQL> ALTER SESSION SET TIME_ZONE = '-5:00';
Session altered.
SQL> SELECT CURRENT_TIMESTAMP, LOCALTIMESTAMP FROM DUAL;

Sample Output:

  CURRENT_TIMESTAMP                      LOCALTIMESTAMP
  ---------------------------------------------------------------------------
    01-MAY-15 02.32.46.226000 AM -05:00  01-MAY-15 02.32.46.226000 AM

Previous: LAST_DAY
Next: MONTHS_BETWEEN



Follow us on Facebook and Twitter for latest update.