Postgresql Localtimestamp Function

PostgreSQL: localtimestamp Function

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

Description

The PostgreSQL localtimestamp function returns the current date and time.

Syntax

The syntax for the localtimestamp function in PostgreSQL is:

localtimestamp( [ precision ] )

Parameters or Arguments

precision

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

Note

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

Applies To

The localtimestamp 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 localtimestamp function examples and explore how to use the localtimestamp function in PostgreSQL.

For example:

postgres=# SELECT localtimestamp;
         timestamp
----------------------------

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

postgres=# SELECT localtimestamp(1);
       timestamp
-----------------------

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

postgres=# SELECT localtimestamp(2);
       timestamp
------------------------

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

postgres=# SELECT localtimestamp(3);
        timestamp
-------------------------

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