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:
EmpID | Name | Login Stamp |
---|---|---|
1 | John | Fri Oct 25 09:20:38.125744 2019 UTC |
2 | Marry | Fri Oct 25 09:21:05.426844 2019 UTC |
3 | Jo | Fri Oct 25 09:24:35.378744 2019 UTC |
4 | Kim | Fri Oct 25 09:25:24.221133 2019 UTC |
5 | Ramesh | Fri 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:
EmpID | Name | Login Stamp |
---|---|---|
1 | John | Fri Oct 25 09:20:38.125744 2019 UTC |
2 | Marry | Fri Oct 25 09:21:05.426844 2019 UTC |
3 | Jo | Fri Oct 25 09:24:35.378744 2019 UTC |
4 | Kim | Fri Oct 25 09:25:24.221133 2019 UTC |
5 | Ramesh | Fri Oct 25 09:27:16.274011 2019 UTC |
6 | Suresh | Fri Oct 25 09:28:19.014011 2019 UTC |
❮ PostgreSQL Functions