Javatpoint Logo
Javatpoint Logo

MySQL Today

How can we get MySQL Today's Date?

We can get the today's date in MySQL using the built-in date function CURDATE(). This function returns the date in 'YYYYMMDD' or 'YYYY-MM-DD' format depending on whether a string or numeric is used in the function. The CURRENT_DATE and CURRENT_DATE() both are the synonyms of the CURDATE() function.

We can use the CURDATE() function as follows:

After the execution of the above queries, we will see the same date. See the below screenshot:

MySQL Today

We can also get today's date by using the NOW() function as follows:

The above query gives the output like the following screenshot:

MySQL Today

Creating the MySQL Today Stored Function

Sometimes we need to use the CURDATE() function multiple times in our queries and want to rename it by the today() function to make the statement more readable. In that case, we can create our own function named today() by creating the stored function as follows:

Now, we are able to use this newly created today() function as follows:

See the below screenshot that explains it more easily:

MySQL Today

Suppose we want to get tomorrow's date, the stored function makes it very easy. See the following query:

After execution, it will return the tomorrow date:

MySQL Today

Suppose we want to get yesterday's date, the stored function can be used like the following query:

After execution, we will get the following output:

MySQL Today

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA