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

PostgreSQL TIMEOFDAY() Function



The PostgreSQL TIMEOFDAY() function returns the actual current date and time with the time zone, and therefore its value changes even within a single SQL command. This function returns the actual current date as a 'DAY MM DD HH:MM:SS.US YYYY TZ' format.

Syntax

TIMEOFDAY()

Parameters

No parameter is required.

Return Value

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

Example 1:

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

SELECT TIMEOFDAY();
Result: 'Sun Apr 17 03:19:44.012873 2022 UTC'

Example 2:

Consider a database table called EmployeeLogin with the following records:

EmpIDNameLogin Stamp
1JohnFri Oct 25 09:20:38.125744 2019 UTC
2MarryFri Oct 25 09:21:05.426844 2019 UTC
3JoFri Oct 25 09:24:35.378744 2019 UTC
4KimFri Oct 25 09:25:24.221133 2019 UTC
5RameshFri Oct 25 09:27:16.274011 2019 UTC

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

INSERT INTO EmployeeLogin 
VALUES (6, 'Suresh', TIMEOFDAY());

-- see the result
SELECT * FROM EmployeeLogin;

This will produce a result similar to:

EmpIDNameLogin Stamp
1JohnFri Oct 25 09:20:38.125744 2019 UTC
2MarryFri Oct 25 09:21:05.426844 2019 UTC
3JoFri Oct 25 09:24:35.378744 2019 UTC
4KimFri Oct 25 09:25:24.221133 2019 UTC
5RameshFri Oct 25 09:27:16.274011 2019 UTC
6SureshFri Oct 25 09:28:19.014011 2019 UTC

❮ PostgreSQL Functions