The Oracle CURRENT_TIMESTAMP
function returns the current date and time in the session time zone.
Noted that the CURRENT_TIMESTAMP
function returns a value of TIMESTAMP WITH TIME ZONE
while the CURRENT_DATE
function returns a value of DATE
without time zone data.
Syntax
The following illustrates the syntax of the Oracle CURRENT_TIMESTAMP
function:
CURRENT_TIMESTAMP(factional_second_precision)
Code language: SQL (Structured Query Language) (sql)
Arguments
1) factional_second_precision
The function accepts an optional argument named factional_second_precision
that determines the number of fractional second precision in the returned time value.
If you omit the factional_second_prevision
argument, it defaults to 6.
Return Value
The Oracle CURRENT_TIMESTAMP
returns a value of the current timestamp in TIMESTAMP WITH TIME ZONE
data type.
Examples
The following statement changes the format of timestamp values to include the time components:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
Code language: SQL (Structured Query Language) (sql)
The following example shows the current timestamp in the session time zone:
SELECT
CURRENT_TIMESTAMP
FROM
dual;
Code language: SQL (Structured Query Language) (sql)
Here is the output:
06-AUG-17 08.26.52.742000000 PM -07:00
Code language: SQL (Structured Query Language) (sql)
Let’s try to change the session time zone to the new one:
ALTER SESSION SET TIME_ZONE = '-08:00';
Code language: SQL (Structured Query Language) (sql)
And get the current timestamp again:
SELECT
CURRENT_TIMESTAMP
FROM
dual;
Code language: SQL (Structured Query Language) (sql)
As you can see, the current timestamp was adjusted to the new session time zone as shown below:
06-AUG-17 07.50.48.004000000 PM -08:00
Code language: SQL (Structured Query Language) (sql)
Remarks
Notice that the CURRENT_TIMESTAMP
returns a TIMESTAMP WITH TIME ZONE
value while the LOCALTIMESTAMP
returns a TIMESTAMP
value without the time zone data.
In this tutorial, you have learned how to use the Oracle CURRENT_TIMESTAMP
function to get the current timestamp in the session time zone.