Postgresql Current_timestamp Function

PostgreSQL: current_timestamp Function

In this PostgreSQL post explains how to use the PostgreSQL current_timestamp function with syntax and examples.

Description

The PostgreSQL current_timestamp function returns the current date and time with the time zone.

Syntax

The syntax for the current_timestamp function in PostgreSQL is:

current_timestamp( [ precision ] )

Parameters or Arguments

precision

Optional. The number of digits to round the fractional seconds to.

Note

  • The current_timestamp function will return the current date as a 'YYYY-MM-DD HH:MM:SS.US+TZ' format.
  • Do not put parentheses () after the current_timestamp function when the precision parameter is not specified.

Applies To

The current_timestamp function can be used in the following versions of PostgreSQL:

  • PostgreSQL 9.4, PostgreSQL 9.3, PostgreSQL 9.2, PostgreSQL 9.1, PostgreSQL 9.0, PostgreSQL 8.4

Example

Let's look at some PostgreSQL current_timestamp function examples and explore how to use the current_timestamp function in PostgreSQL.

For example:

postgres=# SELECT current_timestamp;
              now
-------------------------------

 2014-04-24 20:55:09.808294+00
(1 row)

postgres=# SELECT current_timestamp(1);
       timestamptz
--------------------------

 2014-04-24 20:55:09.8+00
(1 row)

postgres=# SELECT current_timestamp(2);
        timestamptz
---------------------------

 2014-04-24 20:55:09.81+00
(1 row)

postgres=# SELECT current_timestamp(3);
        timestamptz
----------------------------

 2014-04-24 20:55:09.808+00
(1 row)