September 19, 2023
Summary: The PostgreSQL LOCALTIMESTAMP function returns the current date and time at which the current transaction starts.
Table of Contents
Syntax
The following illustrates the syntax of the LOCALTIMESTAMP function:
LOCALTIMESTAMP(precision)
Arguments
The LOCALTIMESTAMP function accepts one argument:
1) precision
The precision argument specifies fractional seconds precision of the second field.
The precision argument is optional. If you omit it, its default value is 6.
Return value
The LOCALTIMESTAMP function returns a TIMESTAMP value that represents the date and time at which the current transaction starts.
Examples
The following example shows how to get the current date and time of the current transaction:
SELECT LOCALTIMESTAMP;
Here is the result:
timestamp
----------------------------
2017-08-16 09:37:38.443431
(1 row)
To get the timestamp of the current transaction with specific fractional seconds precision, you use the precision argument as follows:
SELECT LOCALTIMESTAMP(2);
The result is:
timestamp
------------------------
2017-08-16 09:39:06.64
(1 row)
Remarks
The LOCALTIMESTAMP function returns a TIMESTAMP value without time zone while the CURRENT_TIMESTAMP function returns a TIMESTAMP with time zone.
In this tutorial, you have learned how to use the PostgreSQL LOCALTIMESTAMP function to return the date and time at which the current transaction starts.
See more
PostgreSQL Tutorial: Date Functions
PostgreSQL Documentation: Date/Time Functions and Operators