SQL CURRENT_DATE

Summary: in this tutorial, you will learn how to use the SQL CURRENT_DATE function to get the current date.

To get the current date of the operating system where the database server installed, you use the CURRENT_DATE function as follows:

CURRENT_DATE
Code language: SQL (Structured Query Language) (sql)

See the following example:

SELECT CURRENT_DATE;
Code language: SQL (Structured Query Language) (sql)

The statement returns the following output which is the current date when we execute the statement:

2018-07-21
Code language: SQL (Structured Query Language) (sql)

The CURRENT_DATE is SQL-standard date function supported by almost all database systems such as Firebird, DB2, MySQL 5.x+, MonetDB, Oracle 11.x+, PostgreSQL, and SQLite.

Note that Oracle’s CURRENT_DATE returns both date and time values, therefore, to get the date data, you use the TRUNC function to truncate the time part:

SELECT 
    TRUNC(CURRENT_DATE)
 FROM 
    dual;
Code language: SQL (Structured Query Language) (sql)

SQL Server does not support CURRENT_DATE function. However, it has another function named GETDATE() that returns the current date and time. To get the current date, you use the CAST() function with the GETDATE() function as shown in the following statement:

SELECT CAST(GETDATE() AS DATE) 'Current Date';
Code language: SQL (Structured Query Language) (sql)

In this tutorial, you have learned how to use the SQL CURRENT_DATE function to return the current date.

Was this tutorial helpful ?