How to Get Current Date and Time in MySQL

Sometimes you may need to get date from datetime or get current datetime. In this article, we will look at how to get current date and time in MySQL.


How to Get Current Date and Time in MySQL

There are multiple ways to get current date and time in MySQL.

You can run NOW() function to get current date and time in MySQL.

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2020-12-21 12:18:33 |
+---------------------+

Also read : How to Group By Month in MySQL

You can also use current_timestamp() to get latest date and time in MySQL.

mysql> select current_timestamp();
+---------------------+
| current_timestamp() |
+---------------------+
| 2020-12-21 12:18:33 |
+---------------------+

If you only want to get current date in MySQL, you can use system variable current_date or functions like curdate() or current_date(). They all give latest date in YYYY-MM-DD format.

mysql> select current_date,curdate(),current_date();
+--------------+------------+----------------+
| current_date | curdate()  | current_date() |
+--------------+------------+----------------+
| 2020-12-21   | 2020-12-21 | 2020-12-21     |
+--------------+------------+----------------+

Also read : How to Remove NOT NULL constraint in MySQL

If you only want to get current time in MySQL, you can use system variable current_time or functions like curtime() or current_time(). They all give latest time in HH:MM:SS format

mysql> select current_time,curtime(),current_time();
+--------------+-----------+----------------+
| current_time | curtime() | current_time() |
+--------------+-----------+----------------+
| 12:24:41     | 12:24:41  | 12:24:41       |
+--------------+-----------+----------------+

Also read : How to Remove Default Column Value in MySQL

Need a reporting tool for MySQL? Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!

mm

About Ubiq

Ubiq is a dashboard & reporting platform that makes it easy to get insights from data. Build dashboards, charts & reports for your business in minutes. Try it for free today!