MySQL CURRENT_DATE() function; Through this tutorial, i am going to show you how to use MySQL CURRENT_DATE() with the help of examples.
MySQL CURRENT_DATE() function
The CURRENT_DATE function will return the current date as a ‘YYYY-MM-DD’ format, if used in a string context.
As the name suggest CURDATE() function, basically CURRENT_DATE() function synonym for CURDATE(). Both(CURRENT_DATE(), CURDATE()) functions return the current date as a value in YYYY-MM-DD or YYYYMMDD format.
Syntax of MySQL CURRENT_DATE() function
CURRENT_DATE ()
Example 1 – MySQL CURRENT_DATE() function
The following statement will return the current date in ‘YYYY-MM-DD’ format; as follows:
SELECT CURRENT_DATE();
Output-1
+---------------------+ | CURRENT_DATE() | +---------------------+ | 2019-07-05 | +---------------------+
Example 2 – MySQL CURRENT_DATE() function
The following mysql current_date statement will return the current date in ‘YYYYMMDD’ format; as follows:
SELECT CURRENT_DATE()+1;
Output-2
+---------------------+ | CURRENT_DATE()+1 | +---------------------+ | 20190706 | +---------------------+
Example 3 – MySQL CURRENT_DATE() function
The third example of mysql current_date with day() will return the Day number from current date; as follows:
SELECT DAY(CURRENT_DATE());
Output-3
+---------------------+ | CURRENT_DATE() | +---------------------+ | 5 | +---------------------+
Example 4 – MySQL CURRENT_DATE() function
The following mysql current date with year() function will return the year number from current date; as follows:
SELECT YEAR(CURRENT_DATE());
Output-4
+----------------------+ |YEAR(CURRENT_DATE()) | +----------------------+ | 2019 | +----------------------+
Example 5 – MySQL CURRENT_DATE() function
The following mysql current date with month() function will return the month number from current date; as follows:
SELECT MONTH(CURRENT_DATE());
Output-5
+-------------------------+ |MONTH(CURRENT_DATE()) | +-------------------------+ | 7 | +-------------------------+
Example 6 – MySQL CURRENT_DATE() function
The following mysql current date with week() function will return the week number from current date; as follows:
SELECT WEEK(CURRENT_DATE());
Output-6
+-------------------------+ |WEEK(CURRENT_DATE()); | +-------------------------+ | 26 | +-------------------------+
Example 7 – MySQL CURRENT_DATE() function
The following mysql current date with week() function will return the day from current date; as follows:
SELECT DAYNAME(CURRENT_DATE());
Output-7
+-------------------------+ |DAYNAME(CURRENT_DATE()); | +-------------------------+ | Friday | +-------------------------+
Example 8 – MySQL CURRENT_DATE() function
The following mysql current date with monthname() function will return the month name from current date; as follows:
SELECT MONTHNAME(CURRENT_DATE());
Output-8
+-------------------------+ |DAYNAME(CURRENT_DATE()); | +-------------------------+ | July | +-------------------------+
Conclusion
In this MySQL tutorial, we have discussed MySQL CURRENT_DATE() function with various examples.