MySQL CURDATE() function; In this tutorial, we would love to share with you how to use CURDATE() MySQL function with the help of an example query.
And as well as, we will show you uses of mysql CURDATE() function with various MySQL functions such as YEAR(), MONTH(), WEEK(), DAYNAME(), MONTHNAME() etc.
Basically CURDATE() function returns the present date in various formats, such as ‘YYYY-MM-DD’ or ‘YYYYMMDD’ format.
In our previous tutorial, we have shared a list of MySQL Date functions that are available to work with Date and time.
MySQL CURDATE Function with Examples
In MySQL, The CURDATE() function returns the present date in various formats, such as ‘YYYY-MM-DD’ or ‘YYYYMMDD’ format, depending on whether the numerical or string is used in the function. CURRENT_DATE() is similar to CURDATE().
Both(CURRENT_DATE(), CURDATE()) functions return the current date as a value in YYYY-MM-DD or YYYYMMDD format, depending on whether the function is used in a string or numeric context.
Syntax of MySQL CURDATE Function
CURDATE ()
Examples MySQL CURDATE() function
let’s take various examples of MySQL CURDATE() function.
Example-1
let’s take example-1, the below statement will return the current date in ‘YYYY-MM-DD’ format.
SELECT CURDATE();
Output-1
+------------+ | CURDATE() | +------------+ | 2019-07-05 | +------------+
Example-2
let’s take example-2, the below statement will return the current date in ‘YYYYMMDD’ format.
SELECT CURDATE()+1;
Output-2
+-------------+ | CURDATE()+1 | +-------------+ | 20190706 | +-------------+
Example-3
let’s take example-3, the below statement will return the Day number from current date.
SELECT DAY(CURDATE());
Output-3
+------------+ | CURDATE() | +------------+ | 5 | +------------+
Example-4
let’s take example-4, the below statement will return the year number from current date.
SELECT YEAR(CURDATE());
Output-4
+--------------------+ |YEAR(CURDATE()) | +--------------------+ | 2019 | +--------------------+
Recommended Post
Example-5
let’s take example-5, the below statement will return the month number from current date.
SELECT MONTH(CURDATE());
Output-5
+--------------------+ |MONTH(CURDATE()) | +--------------------+ | 7 | +--------------------+
Example-6
let’s take example-6, the below statement will return the week number from current date.
SELECT WEEK(CURDATE());
Output-6
+--------------------+ |WEEK(CURDATE()); | +--------------------+ | 26 | +--------------------+
Example-7
let’s take example-7, the below statement will return the day name of week from current date.
SELECT DAYNAME(CURDATE());
Output-7
+--------------------+ |DAYNAME(CURDATE()); | +--------------------+ | Friday | +--------------------+
Example-8
let’s take example-8, the below statement will return the month name from current date.
SELECT MONTHNAME(CURDATE());
Output-8
+--------------------+ |DAYNAME(CURDATE()); | +--------------------+ | July | +--------------------+
Conclusion
In this mysql tutorial we have discussed about mysql CURDATE() function with various examples.
Recommended MySQL Tutorials
If you have any questions or thoughts to share, use the comment form below to reach us.