PostgreSQL CURRENT_TIME() Function
The PostgreSQL CURRENT_TIME() function returns the current time with the time zone. This function returns the current time of the day as a 'HH:MM:SS.US+TZ' format.
Syntax
CURRENT_TIME(precision)
Note: Do not put parentheses () after the CURRENT_TIME 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 time with the time zone as a 'HH:MM:SS.US+TZ' format.
Example 1:
The example below shows the usage of CURRENT_TIME() function.
SELECT CURRENT_TIME; Result: '08:01:29.125744+00' SELECT CURRENT_TIME(1); Result: '08:01:29.1+00' SELECT CURRENT_TIME(2); Result: '08:01:29.13+00' SELECT CURRENT_TIME(3); Result: '08:01:29.126+00' SELECT CURRENT_TIME(4); Result: '08:01:29.1257+00'
Example 2:
Consider a database table called EmployeeLogin with the following records:
EmpID | Name | Date | Login Time |
---|---|---|---|
1 | John | 2019-10-25 | 09:20:38+00 |
2 | Marry | 2019-10-25 | 09:21:05+00 |
3 | Jo | 2019-10-25 | 09:24:35+00 |
4 | Kim | 2019-10-25 | 09:25:24+00 |
5 | Ramesh | 2019-10-25 | 09:27:16+00 |
To insert a new record in this table, the following statement can be used.
INSERT INTO EmployeeLogin VALUES (6, 'Suresh', CURRENT_DATE, CURRENT_TIME(0)); -- see the result SELECT * FROM EmployeeLogin;
This will produce a result similar to:
EmpID | Name | Date | Login Time |
---|---|---|---|
1 | John | 2019-10-25 | 09:20:38+00 |
2 | Marry | 2019-10-25 | 09:21:05+00 |
3 | Jo | 2019-10-25 | 09:24:35+00 |
4 | Kim | 2019-10-25 | 09:25:24+00 |
5 | Ramesh | 2019-10-25 | 09:27:16+00 |
6 | Suresh | 2019-10-25 | 09:28:19+00 |
❮ PostgreSQL Functions