MySQL CURDATE Function

MySQL CURDATE() function; In this tutorial, i am going to show you what is MySQL curdate() function and how to use CURDATE() MySQLwith the help of the examples.

MySQL CURDATE Function

MySQLCURDATE() 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().

Syntax of MySQL CURDATE Function

The basic syntax of mysql curdate() function; as follows:

CURDATE ()

Example 1 – MySQL CURDATE() function

The following mysql curdate() function will return the current date in ‘YYYY-MM-DD’ format; as follows:

SELECT CURDATE();

Output-1

 +------------+
 | CURDATE()  |
 +------------+
 | 2019-07-05 | 
 +------------+

Example 1 – MySQL CURDATE() function

The following mysql curdate() will return the current date in ‘YYYYMMDD’ format; as follows:

SELECT CURDATE()+1;

Output-2

 +-------------+
 | CURDATE()+1 |
 +-------------+
 |    20190706 | 
 +-------------+

Example 3 – MySQL CURDATE() + Day() function

The msyql curdate with Day() function will return current date number; as follows:

SELECT DAY(CURDATE());

Output-3

 +------------+
 | CURDATE()  |
 +------------+
 | 5          | 
 +------------+

Example 4 – MySQL CURDATE() + Year() function

The mysql curdate and year() function will return the year number from current date; as follows:

SELECT YEAR(CURDATE());

Output-4

 +--------------------+
 |YEAR(CURDATE())     |
 +--------------------+
 | 2019               | 
 +--------------------+

Example 5 – MySQL CURDATE() + Month() function

The mysql curdate and month() function will return the month number from current date; as follows:

SELECT MONTH(CURDATE());

Output-5

 +--------------------+
 |MONTH(CURDATE())    |
 +--------------------+
 | 7                  | 
 +--------------------+

Example 6 – MySQL CURDATE() + Week() function

The mysql curdate and week() function will return the week number from current date; as follows:

SELECT WEEK(CURDATE());

Output-6

 +--------------------+
 |WEEK(CURDATE());    |
 +--------------------+
 | 26                 | 
 +--------------------+

Example 7 – MySQL CURDATE() + Dayname() function

The mysql curdate and dayname() function will return the day name from current date; as follows:

SELECT DAYNAME(CURDATE());

Output-7

 +--------------------+
 |DAYNAME(CURDATE()); |
 +--------------------+
 | Friday             | 
 +--------------------+

Example 8 – MySQL CURDATE() + MonthName() function

The mysql curdate and monthname() function will return the month name from current date; as follows:

SELECT MONTHNAME(CURDATE());

Output-8

 +--------------------+
 |DAYNAME(CURDATE()); |
 +--------------------+
 | July               | 
 +--------------------+

Conclusion

In this mysql tutorial we have discussed about mysql CURDATE() function with various examples.

Leave a Comment