PostgreSQL - CURRENT_TIME Function
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.
Syntax
CURRENT_TIME(precision)Parameter:
- Precision Argument: The
precisionargument 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.
Return Value:
- The '
CURRENT_TIME'function returns a 'TIME WITH TIME ZONE'value, representing the current time along with the current time zone.
PostgreSQL CURRENT_TIME Function Examples
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 Time
The following statement can be used to get the current time.
Query:
SELECT CURRENT_TIME;Output:
Example 2: Using CURRENT_TIME with Precision
The 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 Value
The 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 Function
We 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 Time
The following statement can be used to get the current time:
SELECT NOW();Output:

Important Points About PostgreSQL CURRENT_TIME Function
- If no precision is specified,
CURRENT_TIMEreturns the time with the full available precision of the underlying data type, which can include microseconds.- In the context of functions and triggers,
CURRENT_TIMEreturns the time at the start of the transaction, not the actual current time at the moment of the call.- The
CURRENT_TIMEfunction returns the current time along with the current time zone. This is different from theCURRENT_TIMEwithout time zone.- While
CURRENT_TIMEreturns only the time part with time zone,CURRENT_TIMESTAMPandNOW()return the full date and time.