PostgreSQL Tutorial: CURRENT_DATE Function

September 19, 2023

Summary: The PostgreSQL CURRENT_DATE function returns the current date.

Table of Contents

Syntax

The CURRENT_DATE function is so simple that requires no argument as follows:

CURRENT_DATE

Return value

The CURRENT_DATE function returns a DATE value that represents the current date.

Examples

The following example shows how to use the CURRENT_DATE function to get the current date:

SELECT CURRENT_DATE;

The output is a DATE value as follows:

2017-08-15

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
);

In the delivery table, we have the delivery_date whose default value is the result of the CURRENT_DATE function.

Second, insert a new row into the delivery table:

INSERT INTO delivery(product)
VALUES('Sample screen protector');

In this 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:

PostgreSQL CURRENT_DATE example

As you can see, the current date was inserted into the delivery_date column.

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.

See more

PostgreSQL Tutorial: Date Functions

PostgreSQL Documentation: Date/Time Functions and Operators