How to Use the MySQL CURRENT_DATE Function
In this tutorial, we'll learn how to use the MySQL CURRENT_DATE function. The CURRENT_DATE function is used to return the current date.
MySQL CURRENT_DATE Syntax
The syntax of the CURRENT_DATE function is as follows:
CURRENT_DATE()
Remark
- This function is equal to the CURDATE() function.
- The date is returned as YYYY-MM-DD format.
CURRENT_DATE Examples
Example 1: Get the Current Date
The following statement returns the current date:
SELECT CURRENT_DATE();
For example, if the current date is July 24th 2019, then this statement returns 2019-07-24.
Example 2: Get and Format the Current Date
The following statement returns the current date in MM/DD/YYYY:
SELECT DATE_FORMAT(CURRENT_DATE(), "%m/%d/%Y ");
For example, if the current date is July 24th 2019, then this statement returns 07/24/2019. Here, we used the DATE_FORMAT function to format the current date returned from the CURRENT_DATE function.
Example 3: Subtract 4 Months from the Current Date
The following statement returns the current date - 4 months:
SELECT DATE_SUB(CURRENT_DATE(),INTERVAL 4 MONTH);
For example, if the current date is July 24th 2019, then this statement returns 03/24/2019. Here, we used the DATE_SUB function to subtract 4 months from the current date.
Example 4: Add 3 Years to the Current Date
The following statement returns the current date + 3 years:
SELECT DATE_ADD(CURRENT_DATE(),INTERVAL 3 YEAR);
For example, if the current date is July 24th 2019, then this statement returns 07/24/2022. Here, we used the DATE_ADD function to add 3 years to the current date.
In this tutorial, we've learned how to use the MySQL CURRENT_DATE function. CURRENT_DATE is a function to return the current date.