PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References
PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References

PostgreSQL LOCALTIMESTAMP() Function



The PostgreSQL LOCALTIMESTAMP() function returns the current date and time. This function returns the current date as a 'YYYY-MM-DD HH:MM:SS.US' format.

Syntax

LOCALTIMESTAMP(precision)

Note: Do not put parentheses () after the LOCALTIMESTAMP function if the precision parameter is not specified.

Parameters

precision Optional. Specify the number of digits to round the fractional seconds to. It must be an integer between 0 to 6.

Return Value

Returns the current date as a 'YYYY-MM-DD HH:MM:SS.US' format.

Example 1:

The example below shows the usage of LOCALTIMESTAMP() function.

SELECT LOCALTIMESTAMP;
Result: '2021-12-27 08:01:29.125744'

SELECT LOCALTIMESTAMP(1);
Result: '2021-12-27 08:01:29.1'

SELECT LOCALTIMESTAMP(2);
Result: '2021-12-27 08:01:29.13'

SELECT LOCALTIMESTAMP(3);
Result: '2021-12-27 08:01:29.126'

SELECT LOCALTIMESTAMP(4);
Result: '2021-12-27 08:01:29.1257'

Example 2:

Consider a database table called EmployeeLogin with the following records:

EmpIDNameLogin Stamp
1John2019-10-25 09:20:38
2Marry2019-10-25 09:21:05
3Jo2019-10-25 09:24:35
4Kim2019-10-25 09:25:24
5Ramesh2019-10-25 09:27:16

To insert a new record in this table, the following statement can be used.

INSERT INTO EmployeeLogin 
VALUES (6, 'Suresh', LOCALTIMESTAMP(0));

-- see the result
SELECT * FROM EmployeeLogin;

This will produce a result similar to:

EmpIDNameLogin Stamp
1John2019-10-25 09:20:38
2Marry2019-10-25 09:21:05
3Jo2019-10-25 09:24:35
4Kim2019-10-25 09:25:24
5Ramesh2019-10-25 09:27:16
6Suresh2019-10-25 09:28:19

❮ PostgreSQL Functions