PostgreSQL - CURRENT_TIME Function
Last Updated :
17 Jul, 2024
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
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.
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:
OutputImportant 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 the CURRENT_TIME
without time zone. - While
CURRENT_TIME
returns only the time part with time zone, CURRENT_TIMESTAMP
and NOW()
return the full date and time.
Similar Reads
PostgreSQL - CURRENT_TIMESTAMP Function PostgreSQL provides the 'CURRENT_TIMESTAMP() function, which returns the current date and time, along with the time zone, at the precise moment the transaction begins. This function is often used for tracking the creation or modification of records in a database.Here, weâll look into the syntax, usa
2 min read
PostgreSQL - CURRENT_DATE Function The PostgreSQL CURRENT_DATE function is used to retrieve the current date. Itâs a simple and effective way to ensure your database operations are using the correct date, particularly for applications that need timestamp records.Let us better understand the CURRENT_DATE Function in PostgreSQL from th
2 min read
PostgreSQL TO_TIMESTAMP() Function In PostgreSQL, managing and manipulating date and time values is important, especially when they are stored as strings. The to_timestamp function allows us to convert textual representations of dates and times into a valid timestamp format and making it easier to work with them in queries, calculati
5 min read
PostgreSQL Date Functions PostgreSQL is widely recognized for its comprehensive support for date and time manipulations, making it an excellent choice for applications requiring precise time management and complex calculations. This article explores the core PostgreSQL date functions, covering how to retrieve the current dat
4 min read
PostgreSQL - DATE_TRUNC Function The PostgreSQL DATE_TRUNC() function is a powerful tool that helps us truncate a timestamp or interval to a specified level of precision. It is particularly useful when dealing with time-based data for effective data grouping and manipulation, making it ideal for reporting, analytics, and queries wh
4 min read
PostgreSQL - NOW() Function The NOW() function in PostgreSQL is a powerful and essential tool for retrieving the current date and time. This is particularly useful when recording actions like adding or updating records in our database. Using PostgreSQL NOW() function, we can efficiently track when events occur, making the data
4 min read
PostgreSQL DATE_PART Function Handling dates and times efficiently is essential for data-driven applications, and PostgreSQL provides powerful built-in functions for managing and manipulating time-based data. One such function is the DATE_PART() function, which allows us to extract specific subfields from date and timestamp valu
5 min read
PostgreSQL - TIME Data Type In PostgreSQL, the TIME data type is essential for applications that require precise time tracking, such as scheduling systems and event logging. This data type allows for accurate time-based entries without storing date information. PostgreSQLâs TIME data type also supports fractional seconds for u
4 min read
PostgreSQL - Date Data Type PostgreSQL offers powerful DATE data type and date functions to efficiently handle date and time information. PostgreSQL DATE data type allows for storing and manipulating calendar dates while its robust set of date functions enables users to perform operations like date arithmetic and formatting. I
4 min read