Last Updated : 15 Jul, 2025
The PostgreSQL CURRENT_TIME
function returns the current time and the current time zone. This function is handy when you need to work with time-sensitive data in your database applications.
Let us better understand the CURRENT_TIME Function in PostgreSQL from this article.
SyntaxCURRENT_TIME(precision)Parameter:
precision
argument sets the precision of the returned 'TIME'
type value in fractional seconds. If no precision is specified, the function returns the full available precision by default.CURRENT_TIME'
function returns a 'TIME WITH TIME ZONE'
value, representing the current time along with the current time zone.Let us take a look at some of the examples of CURRENT_TIME Function in PostgreSQL to better understand the concept.
Example 1: Getting the Current TimeThe following statement can be used to get the current time.
Query:
SELECT CURRENT_TIME;
Output:
Example 2: Using CURRENT_TIME with PrecisionThe following statement shows the process of using the CURRENT_TIME function with the precision of 2.
Query:
SELECT CURRENT_TIME(2);
Output:
Example 3: Using CURRENT_TIME as a Default ValueThe CURRENT_TIME function can also be used as the default value of the TIME columns. To demonstrate this, create a table named 'log':
CREATE TABLE log (
log_id SERIAL PRIMARY KEY,
message VARCHAR(255) NOT NULL,
created_at TIME DEFAULT CURRENT_TIME,
created_on DATE DEFAULT CURRENT_DATE
);
The 'log' table has the 'created_at' column whose default value is the value returned by the 'CURRENT_TIME' function. Now insert some data to the 'demo' table:
INSERT INTO log( message )
VALUES('Testing the CURRENT_TIME function');
Now verify if the row was inserted into the log table with the created_at column added correctly by using the following query:
SELECT * FROM log;
Output:
Alternative: Using the PostgreSQL NOW FunctionWe can get similar output by using by Postgresql NOW function.
Syntax: NOW();
This will return the current date and time in the following format: 'YYYY-MM-DD HH:MI: SS.MS+TZ'.
Example 1: Getting the Current Date and TimeThe following statement can be used to get the current time:
SELECT NOW();
Output:
Output Important Points About PostgreSQL CURRENT_TIME Function
- If no precision is specified,
CURRENT_TIME
returns the time with the full available precision of the underlying data type, which can include microseconds.- In the context of functions and triggers,
CURRENT_TIME
returns the time at the start of the transaction, not the actual current time at the moment of the call.- The
CURRENT_TIME
function returns the current time along with the current time zone. This is different from theCURRENT_TIME
without time zone.- While
CURRENT_TIME
returns only the time part with time zone,CURRENT_TIMESTAMP
andNOW()
return the full date and time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4