There are different ways in MySQL through which we can find out today’s date using a single query. In this post, all the approaches through which we can find out today’s date are being discussed in detail.
How to get today’s date in a query in MySQL
There are different ways through which we can find out the present date, some of them are:
- Using the CURRENT_TIMESTAMP()
- Using the NOW()
- Using the CURDATE()
These are all explained in detail.
Today’s date using the CURDATE() function in MySQL
The other way to find the present date in MySQL is by using the function of CURDATE() with SELECT clause, for example:
The output displayed the current date, we can also use the synonym of curdate that is “CURRENT_DATE()”:
Today’s date using the NOW() function in MySQL
This is the built-in function that will return the present date and time in MySQL, we can use it with the SELECT clause, for example:
If we want to extract only the present date from the function of NOW(), use the DATE() function along with the NOW() function, for example:
We can see from the output, the present date has been extracted from the NOW() function using the DATE() function.
Today’s date using the Current_timestamp() function in MySQL
The current_timestamp() is used to return the current time and date in MySQL, for example:
If we want to extract only date from it, then we can use the DATE() function with it:
From the above output, we have extracted the date.
Conclusion
MySQL is enriched with a lot of functions which make it very much easy for its users to perform their tasks efficiently. One of its examples is discussed in this post, if you are working on a MySQL database and want to access the date then it allows you some of the functions with which you can find out today’s date by simply running a query. In this post, we have discussed different functions and their usages through which we can find out today’s date easily in MySQL.