Postgresql Localtime Function

PostgreSQL: localtime Function

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

Description

The PostgreSQL localtime function returns the current time.

Syntax

The syntax for the localtime function in PostgreSQL is:

localtime( [ precision ] )

Parameters or Arguments

precision

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

Note

  • The localtime function will return the current time of day as a 'HH:MM:SS.US' format.
  • Do not put parentheses () after the localtime function when the precision parameter is not specified.

Applies To

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

For example:

postgres=# SELECT localtime;
      time
-----------------

 20:18:08.586881
(1 row)

postgres=# SELECT localtime(1);
    time
------------

 20:18:08.6
(1 row)

postgres=# SELECT localtime(2);
    time
-------------

 20:18:08.59
(1 row)

postgres=# SELECT localtime(3);
     time
--------------

 20:18:08.587
(1 row)