Db2 Current Timestamp

Summary: in this tutorial, you will learn how to use Db2 CURRENT_TIMESTAMP and CURRENT TIMESTAMP functions to get the current timestamp of the operating system on which the Db2 is running.

To get the current timestamp of the operating system on which the Db2 is running, you use the CURRENT_TIMESTAMP function:

SELECT CURRENT_TIMESTAMP result FROM sysibm.sysdummy1;
Code language: SQL (Structured Query Language) (sql)

Here is the result:

RESULT ------------------------- 2019-06-14 10:59:26.988
Code language: SQL (Structured Query Language) (sql)

It is possible to use the CURRENT TIMESTAMP without the underscore (_) character between the CURRENT and TIMESTAMP keywords:

SELECT CURRENT TIMESTAMP result FROM sysibm.sysdummy1;
Code language: SQL (Structured Query Language) (sql)

Besides the SELECT statement, you can use the VALUES keyword to get the current timestamp:

VALUES CURRENT_TIMESTAMP VALUES CURRENT TIMESTAMP
Code language: SQL (Structured Query Language) (sql)

From the current timestamp, you can extract the year, month, day, hour, minute, and microsecond:

SELECT YEAR (current timestamp) current_year, MONTH (current timestamp) current_month, DAY (current timestamp) current_day, HOUR (current timestamp) current_hour, MINUTE (current timestamp) current_minute, SECOND (current timestamp) current_second, MICROSECOND (current timestamp) current_microsecond FROM sysibm.sysdummy1;
Code language: SQL (Structured Query Language) (sql)

The following picture shows the result:

db2 current_timestamp
Was this tutorial helpful ?