Home  >  Article  >  Database  >  MySQL query to get current date time and only current date

MySQL query to get current date time and only current date

WBOY
WBOYforward
2023-09-04 19:45:03877browse

MySQL query to get current date time and only current date

Query SELECT NOW() gives the current date and current time. Only use CURDATE() if you only need the current date. The following is the syntax for datetime -

SELECT NOW();

The syntax for date only.

SELECT CURDATE();

Let us now implement the above syntax −

Case 1: If you want the 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 only want the current date -

mysql> SELECT CURDATE();

Output

+------------+
| CURDATE()  |
+------------+
| 2019-06-02 |
+------------+
1 row in set (0.00 sec)

The above is the detailed content of MySQL query to get current date time and only current date. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete