Back to cookbooks list Articles Cookbook

How to Get the Current Date in MySQL

  • CURDATE()

Table of Contents

Problem:

You’d like to get the current date in MySQL.

Solution:

Use the CURDATE() function. Here’s the query:

SELECT CURDATE();

Here’s the result of the query:

2021-03-03

Discussion:

Discover the best interactive MySQL courses

Simply use the CURDATE() function to get the current date.

The date can be displayed in two different formats: ‘YYYY-MM-DD' if it is used in a string context or YYYYMMDD if it is used in a numeric context.

What does it mean to be used in a string or numeric context? Let’s see an example of a query in a string context:

SELECT CURDATE();

And the result:

2021-03-03

An example of a query in a numeric context:

SELECT CURDATE() + 0;

Which will result in:

20210303

There are two other functions that can be used instead of CURDATE(): CURRENT_DATE and CURRENT_DATE(). All three are synonyms; that is, you can choose any of them and the result will be the same.

Recommended courses:

Recommended articles:

See also: