PostgreSQL Tutorial: LOCALTIME Function

September 19, 2023

Summary: The PostgreSQL LOCALTIME function returns the current time at which the current transaction starts.

Table of Contents

Syntax

The syntax of the LOCALTIME function is as follows:

LOCALTIME(precision)

Arguments

The LOCALTIME function takes one optional argument:

1) precision

The precision argument specifies fractional seconds precision of the second field.

If you omit the argument, it defaults to 6.

Return Value

The LOCALTIME function returns a TIME value that represents the time at which the current transaction starts.

Examples

The following query illustrates how to get the time of the current transaction:

SELECT LOCALTIME;

Here is the result:

      time
-----------------
 09:52:20.751278
(1 row)

The get the time with a specified fractional seconds precision, you use the following statement:

SELECT LOCALTIME(2);

The result is:

     time
-------------
 09:53:10.74
(1 row)

Remarks

Noted that the LOCATIME function returns a TIME value without time zone while the CURRENT_TIME function returns a TIME with time zone.

In this tutorial, you have learned how to use the PostgreSQL LOCALTIME function to get the time at which the current transaction starts.

See more

PostgreSQL Tutorial: Date Functions

PostgreSQL Documentation: Date/Time Functions and Operators