Oracle CURRENT_TIMESTAMP Function: A Simple Guide

The CURRENT_TIMESTAMP function in Oracle SQL returns the exact current date, time, and time zone of your SQL session.

Its key feature is that it returns a TIMESTAMP WITH TIME ZONE data type. This means the output includes not just the date and time (down to fractional seconds), but also the session's time zone offset (like -05:00 or +08:00).

What is the CURRENT_TIMESTAMP Function in Oracle?

The CURRENT_TIMESTAMP function is a precise way to get the current time including the time zone offset.

This makes it different from:

  • LOCALTIMESTAMP: Returns a TIMESTAMP value without the time zone offset.
  • CURRENT_DATE: Returns a DATE value, which includes date and time but has no fractional seconds or time zone.
  • SYSDATE / SYSTIMESTAMP: These return the date/time of the database server's operating system, not necessarily your session's time zone.

CURRENT_TIMESTAMP is ideal when you need to record the exact moment an event happened in a way that is sensitive to the user's local time zone.

CURRENT_TIMESTAMP Function Syntax

The syntax for CURRENT_TIMESTAMP is:

CURRENT_TIMESTAMP [ (precision) ]

Let's break that down:

  • precision (Optional): An integer from 0 to 9 that specifies the number of digits for fractional seconds. The default is 6.

Oracle CURRENT_TIMESTAMP Function Examples

Here are two practical examples of how to use CURRENT_TIMESTAMP.

Example 1: Basic CURRENT_TIMESTAMP Function Call

This example shows the default output of the function, which includes the date, time (to 6 decimal places for seconds), and the session's current time zone offset.

Query:

SELECT 
  CURRENT_TIMESTAMP 
FROM DUAL;

Result: (Your result will be different, but will follow this format.)

CURRENT_TIMESTAMP
---------------------------------------------------------------------------
06-NOV-25 04.07.15.123456 PM +05:30

Example 2: Showing Time Zone Sensitivity with CURRENT_TIMESTAMP

The main feature of CURRENT_TIMESTAMP is that it changes based on your session's time zone. This example shows how the output changes when we alter the session.

Query:

-- First, set the time zone to New York (UTC-5:00)
ALTER SESSION SET TIME_ZONE = '-5:00';
SELECT 
  SESSIONTIMEZONE, 
  CURRENT_TIMESTAMP 
FROM DUAL;

-- Now, set the time zone to Los Angeles (UTC-8:00)
ALTER SESSION SET TIME_ZONE = '-8:00';
SELECT 
  SESSIONTIMEZONE, 
  CURRENT_TIMESTAMP 
FROM DUAL;

Result:

SESSIONTIMEZONE CURRENT_TIMESTAMP
--------------- -----------------------------------
-05:00          06-NOV-25 05.30.10.456789 AM -05:00

SESSIONTIMEZONE CURRENT_TIMESTAMP
--------------- -----------------------------------
-08:00          06-NOV-25 02.30.10.456789 AM -08:00

Notice how the time itself (and the offset) automatically changed to reflect the new session time zone.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted