SQL Tutorial SQL Advanced SQL Database SQL References

Oracle CURRENT_TIMESTAMP Function



The Oracle (PL/SQL) CURRENT_TIMESTAMP function returns the current date and time in the time zone of the current SQL session, in a value of datatype TIMESTAMP WITH TIME ZONE. The time zone offset reflects the current local time of the SQL session.

Note: The difference between this function and LOCALTIMESTAMP is that CURRENT_TIMESTAMP returns a TIMESTAMP WITH TIME ZONE value while LOCALTIMESTAMP returns a TIMESTAMP value.

Syntax

/* without precision argument */
CURRENT_TIMESTAMP

/* with precision argument */
CURRENT_TIMESTAMP(precision)

Parameters

precision Optional. Specify the fractional second precision of the time value returned. Default value is 6.

Return Value

Returns the current date and time in the time zone of the current SQL session.

Example 1:

The example below shows the usage of CURRENT_TIMESTAMP function.

CURRENT_TIMESTAMP
Result: '27-DEC-2021 05.11.57.276814 AM US/PACIFIC'

CURRENT_TIMESTAMP(6)
Result: '27-DEC-2021 05.11.57.276814 AM US/PACIFIC'

CURRENT_TIMESTAMP(5)
Result: '27-DEC-2021 05.11.57.276810 AM US/PACIFIC'

CURRENT_TIMESTAMP(4)
Result: '27-DEC-2021 05.11.57.276800 AM US/PACIFIC'

Example 2:

The example below illustrates that CURRENT_TIMESTAMP is sensitive to the session time zone:

ALTER SESSION SET TIME_ZONE = '-5:0';
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP FROM DUAL;

Result:
SESSIONTIMEZONE CURRENT_TIMESTAMP
--------------- ---------------------------------------------------
-05:00          04-APR-00 01.17.56.917550 PM -05:00


ALTER SESSION SET TIME_ZONE = '-8:0';
SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP FROM DUAL;

Result:
SESSIONTIMEZONE CURRENT_TIMESTAMP
--------------- ----------------------------------------------------
-08:00          04-APR-00 10.18.21.366065 AM -08:00

Example 3:

Consider a database table called EmployeeLogin with the following records:

EmpIDNameLogin Stamp
1John25-OCT-2019 09.20.38.276815 AM US/PACIFIC
2Marry25-OCT-2019 09.21.05.123456 AM US/PACIFIC
3Jo25-OCT-2019 09.24.35.654321 AM US/PACIFIC
4Kim25-OCT-2019 09.25.24.122433 AM US/PACIFIC
5Ramesh25-OCT-2019 09.27.16.556711 AM US/PACIFIC

To insert a new record in this table, the following statement can be used.

INSERT INTO EmployeeLogin 
VALUES (6, 'Suresh', CURRENT_TIMESTAMP);

-- see the result
SELECT * FROM EmployeeLogin;

This will produce a result similar to:

EmpIDNameLogin Stamp
1John25-OCT-2019 09.20.38.276815 AM US/PACIFIC
2Marry25-OCT-2019 09.21.05.123456 AM US/PACIFIC
3Jo25-OCT-2019 09.24.35.654321 AM US/PACIFIC
4Kim25-OCT-2019 09.25.24.122433 AM US/PACIFIC
5Ramesh25-OCT-2019 09.27.16.556711 AM US/PACIFIC
6Suresh25-OCT-2019 09.28.19.298518 AM US/PACIFIC

❮ Oracle Functions