MySQL CURRENT_DATE() Function
In this context, we will learn how we can use the MySQL CURRENT_DATE() function to get the current date, and we will see in the two formats, such as strings and numeric, respectively.
Introduction of MySQL CURRENT_DATE()function:
We will see in this function how we can use the current date function. In this, there are two formats for getting the current date by this function, such as “ YYYY – MM – DD”, which is in string format or YYYYMMDD, which is in numeric format.
Syntax of CURRENT_DATE() function in MySQL
CURRENT_DATE()
Parameter used in CURRENT_DATE()function
There is no parameter accepted by this method.
Returns:
The current date is returned in this.
Important points of MySQL CURRENT_DATE() function:
- If we are using the string format, then we will get the current date as a ‘ YYYY – MM – DD’ from the CURRENT_DATE() function.
- On the other hand, if we are using the numeric context, then we will get the current date as a YYYYMMDD from the CURRENT _DATE function.
- The CURRENT_DATE()function is a synonym for the CUR_DATE function.
Application used for CURRENT_DATE() function:
The CURRENT_DATE()function is used in the given below MySQL versions.
- MySQL 5.7
- MySQL 5.6
- MySQL 5.5
- MySQL 5.1
- MySQL 5.0
- MySQL 4.1
- MySQL 4.0
- MySQL 3.23
Example:
Describe the method in which the CURRENT_DATE() () function is used in the context of the string to get the current date.
SELECT CURRENT_DATE() AS CURR_DATE ;
Output:
CURR_DATE
2019 – 08 – 17
1 row in set (0.00 sec)
Example:
Write the method in which the CURRENT_DATE() function is used to find the present date in YYYYMMDD format, which is the numeric format.
SELECT CURRENT_DATE() + 0 AS CURR_DATE ;
Output:
CURR_DATE
20190817
1 row in set (0.00 sec)
/
Example:
In this example, we will see how we can get the next 5 days' date by the CURRENT_DATE() function in the YYYYMMDD format.
SELECT CURRENT_DATE() +5 AS NEXT_DATE ;
Output:
NEXT _DATE
20190822
1 row in set (0.00 sec)
Example:
This example shows how we can get the date 6 days before the current date in the format of YYYYMMDD, which is a numeric context.
SELECT CURRENT_DATE() – 6 AS PREV_DATE ;
Output:
PREV_DATE
20190810
1 row in set (0.00 sec)
Application of MySQL CURRENT_DATE()function:
This function is used to get the current date in MySQL in two formats.
Summary:
In the above context, we have learned how we can use the CURRENT_DATE() function in MySQL used to get the current date in MySQL in two formats.