How to Get the Current Date in MySQL using CURDATE()
In this tutorial, you'll learn how to use the MySQL CURDATE() function. CURDATE() is a function to return the current date.
MySQL CURDATE() Syntax
The syntax of the CURDATE() function is as follows:
CURDATE()
Remark
- This function is equal to the CURRENT_DATE() function
- MySQL returns the date as a YYYY-MM-DD format
Examples
Example 1
The following statement returns the current date:
SELECT CURDATE();
For example, if the current date is May 11th, 2019, then this statement returns 2019-05-11.
Example 2
The following statement returns the current date in MM/DD/YYYY:
SELECT DATE_FORMAT(CURDATE(), "%m/%d/%Y ");
For example, if the current date is May 11th, 2019, then MySQL returns 05/11/2019.
Here, DATE_FORMAT() function formats the current date returned from CURDATE().
Example 3
The following statement returns the current date + 2 months:
SELECT DATE_ADD(CURDATE(),INTERVAL 2 MONTH);
For example, if the current date is May 11th, 2019, then this statement returns 07/11/2019.
Here, DATE_ADD() function adds two months to the current date.
Example 4
The following statement returns the current date - 2 years:
SELECT DATE_SUB(CURDATE(),INTERVAL 2 YEAR);
For example, if the current date is May 11th, 2019, then the statement returns 05/11/2017.
Here, DATE_SUB() subtracts two years from the current date.
In this tutorial, you've learned how to use the MySQL CURDATE() function. CURDATE() is used to return the current date.