September 19, 2023
CURRENT_DATE function returns the current date.
CURRENT_DATE function is so simple that requires no argument as follows:
CURRENT_DATE function returns a
DATE value that represents the current date.
The following example shows how to use the
CURRENT_DATE function to get the current date:
The output is a
DATE value as follows:
You can use the
CURRENT_DATE function as a default value of a column. Consider the following example.
First, 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 );
delivery table, we have the
delivery_date whose default value is the result of the
Second, insert a new row into the
INSERT INTO delivery(product) VALUES('Sample screen protector');
INSERT statement, we did not specify the delivery date, therefore, PostgreSQL used the current date as the default value.
Third, verify whether the row was inserted successfully with the current date by using the following query:
SELECT * FROM delivery;
The following picture illustrates the result:
As you can see, the current date was inserted into the
Noted that you may see a different value in the
delivery_date column, depending on the date you execute the query.
In this tutorial, you have learned how to use the PostgreSQL
CURRENT_DATE function to get the current date.