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:
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:
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:
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:
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:
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:
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:
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.