PostgreSQL – CURRENT_DATE Function
The PostgreSQL CURRENT_DATE function returns the current date.
Syntax: CURRENT_DATE
Return value:
The CURRENT_DATE function returns a DATE value that represents the current date.
Example 1:
The following statement shows how to use the CURRENT_DATE function to get the current date:
SELECT CURRENT_DATE;
Output:
Example 2:
The CURRENT_DATE function can be used as a default value of a column. So create a table named delivery for demonstration:
CREATE TABLE delivery( delivery_id serial PRIMARY KEY, product varchar(255) NOT NULL, delivery_date DATE DEFAULT CURRENT_DATE );
In the delivery table, there is the delivery_date whose default value is the result of the CURRENT_DATE function. Let’s add some data to it.
INSERT INTO delivery(product) VALUES('Data Structure And Algorithm Edition 1');
Third, verify whether the row was inserted successfully with the current date by using the following:
SELECT * FROM delivery;
Output:
Contact Us