PostgreSQL Tutorial

  • Home
  • Stored Procedures
  • Triggers
  • Views
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
  • Functions
    • Aggregate Functions
    • Date / Time Functions
    • String Functions
    • Math Functions
Home / PostgreSQL Date Functions / PostgreSQL CURRENT_DATE

PostgreSQL CURRENT_DATE

The PostgreSQL CURRENT_DATE function returns the current date.

Syntax

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

1
CURRENT_DATE

Return value

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

Examples

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

1
SELECT CURRENT_DATE;

The output is a DATE value as follows:

1
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:

1
2
3
4
5
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:

1
2
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:

1
2
3
4
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.

Previous Tutorial: PostgreSQL AGE Function
Next Tutorial: PostgreSQL CURRENT_TIME

PostgreSQL Date Functions

  • AGE
  • CURRENT_DATE
  • CURRENT_TIME
  • CURRENT_TIMESTAMP
  • EXTRACT
  • LOCALTIME
  • LOCALTIMESTAMP
  • DATE_PART
  • DATE_TRUNC
  • NOW
  • TO_DATE

About PostgreSQL Tutorial

PostgreSQLTutorial.com is a website dedicated to developers and database administrators who are working on PostgreSQL database management system.

We constantly publish useful PostgreSQL tutorials to keep you up-to-date with the latest PostgreSQL features and technologies. All PostgreSQL tutorials are simple, easy-to-follow and practical.

Recent PostgreSQL Tutorials

  • PostgreSQL TRUNC
  • PostgreSQL ROUND
  • PostgreSQL Math Functions
  • PostgreSQL LOCALTIME
  • PostgreSQL LOCALTIMESTAMP
  • PostgreSQL CURRENT_TIMESTAMP
  • PostgreSQL CURRENT_TIME
  • PostgreSQL CURRENT_DATE
  • PostgreSQL Date Functions
  • PostgreSQL EXTRACT

More Tutorials

  • PostgreSQL Cheat Sheet
  • PostgreSQL Administration
  • PostgreSQL PHP
  • PostgreSQL Python
  • PostgreSQL JDBC
  • PostgreSQL Resources

Site Info

  • Home
  • About Us
  • Contact Us
  • Privacy Policy

Copyright © 2017 by PostgreSQL Tutorial Website. All Rights Reserved.