MySQL CURDATE() Function Manipulation Examples

In MySQL CURDATE() function tutorial, we would love to share with you how to use CURDATE() MySQL in query. We will provide various examples of CURDATE() function in this tutorial. We will show you uses of mysql CURDATE() with various MySQL function 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() & 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:

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               | 
 +--------------------+

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.

If you have any questions or thoughts to share, use the comment form below to reach us.

Spread the love

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *