MySQL MariaDB

How Would You Get the Current Date in MySQL?

MySQL is one of the popular relational databases that provide the ability to handle massive amounts of data efficiently. One of the common tasks while working with databases is obtaining the current date, as it is an essential piece of information in many applications. MySQL has many functions that come built-in that can ease the user when performing this task.

This post will provide examples to get the current date in MySQL. Before beginning with this post, make sure that you have logged in to the local MySQL server using the Command Prompt.

Get the Current Date Using “CURDATE()” Function

The “CURDATE” function aids in extracting the current date in the string format “YYYY-MM-DD” by default, which can change to numeric format even. The command is provided below:

SELECT CURDATE();

The output is providing the current date in the string format extracted using the “CURDATE()” function:

Get the Current Date Using “CURRENT_DATE()” Function

The “CURRENT_DATE()” function’s functionality is similar to “CURDATE()”, to get the current time of the system use this function with the “SELECT” statement by running the command:

SELECT CURRENT_DATE();

The output is showing the current date using “CURRENT_DATE()” function:

Get the Current Date Using “NOW()” Function

The “NOW()” function is used to get the current time and date in the string format “YYYY-MM-DD HH-MM-SS”, which can be changed to numeric format “YYYYMMDDHHMMSS.uuuuuu” by adding “+ 0” after the “NOW()”. The command to get the current date and time is given below:

SELECT NOW();

The output displays the current date and time:

If the user wants to extract the current date, only use the “NOW()” function. Place it inside the “DATE()” function, which takes the date and time to return the formatted date. Run this command given below:

SELECT DATE(NOW());

The output displays the current date:

Get the Current Date Using “CURRENT_TIMESTAMP()” Function

The user can also use the “CURRENT_TIMESTAMP()” with the following command:

SELECT CURRENT_TIMESTAMP();

The output displays the current date and time:

The “CURRENT_TIMESTAMP()” function should be placed inside the “DATE()” function to return the formatted date. For this use the follow query:

SELECT DATE(CURRENT_TIMESTAMP());

The current date is showing in the output:

Get the Current Date Using “UTC_DATE()” Function

The “UTC_DATE()” function obtains the current date according to Coordinated Universal Time(UTC) in the format “YYYY-MM-DD”. Run the command given below:

SELECT UTC_DATE();

You have successfully obtained the current date in MySQL:

That concludes all of the methods to get the current date in MySQL.

Conclusion

In MySQL, user can obtain the current date using “SELECT CURDATE();”, “SELECT UTC_DATE();”, “SELECT DATE(CURRENT_TIMESTAMP());”, “SELECT DATE(NOW());” or “SELECT CURRENT_DATE();” command. These commands provide the date in string format that can even be converted to numeric format even. This post discussed different commands to get the current date in MySQL.

About the author

Abdul Mannan

I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor's degree in computer science.