MySQL query to get current datetime and only current date


The query SELECT NOW() gives the current date as well as current time. If you want only current date, use only CURDATE(). Following is the syntax for datetime −

SELECT NOW();

The syntax for only date.

SELECT CURDATE();

Let us now implement the above syntax −

Case 1 : If you want both current date and time −

mysql> SELECT NOW();

Output

+-----------------------+
| NOW()                 |
+-----------------------+
| 2019-06-02 15 :30 :39 |
+-----------------------+
1 row in set (0.00 sec)

Case 2 : If you want the current date only −

mysql> SELECT CURDATE();

Output

+------------+
| CURDATE()  |
+------------+
| 2019-06-02 |
+------------+
1 row in set (0.00 sec)
raja
Published on 13-Jun-2019 12:25:40
Advertisements