A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/postgresql/postgresql-current_time-function/ below:

PostgreSQL - CURRENT_TIME Function - GeeksforGeeks

PostgreSQL - CURRENT_TIME Function

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.

Syntax
CURRENT_TIME(precision)
Parameter: Return Value: 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:

Output Important Points About PostgreSQL CURRENT_TIME Function


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