MySQL CURDATE() Function with Examples


How to Use the MySQL CURDATE() Function

In this tutorial, we'll learn how to use the MySQL CURDATE() function. CURDATE() is a function to return the current date.

MySQL CURDATE() Syntax

The syntax of the CURDATE() function is as follows:

CURDATE()

Remark

  • This function is equal to the CURRENT_DATE() function.
  • The date is returned as YYYY-MM-DD format.

Examples

Example 1

The following statement return the current date:

SELECT CURDATE();

For example, if the current date is May 11th 2019, then this statement returns 2019-05-11.

Example 2

The following statement returns the current date in MM/DD/YYYY:

SELECT DATE_FORMAT(CURDATE(), "%m/%d/%Y ");

For example, if the current date is May 11th 2019, then this statement returns 05/11/2019. Here, we used the DATE_FORMAT() function to format the current date returned from the CURDATE() function.

Example 3

The following statement returns the current date + 2 months:

SELECT DATE_ADD(CURDATE(),INTERVAL 2 MONTH);

For example, if the current date is May 11th 2019, then this statement returns 07/11/2019. Here, we used the DATE_ADD() function to add 2 months to the current date.

Example 4

The following statement returns the current date - 2 years:

SELECT DATE_SUB(CURDATE(),INTERVAL 2 YEAR);

For example, if the current date is May 11th 2019, then this statement returns 05/11/2017. Here, we used the DATE_SUB() function to subtract 2 years from the current date.

In this tutorial, we've learned how to use the MySQL CURDATE() function. CURDATE() is used to return the current date.

Leave a Reply

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