Home > Database > Mysql Tutorial > body text

MySQL query to get current date time and only current date

WBOY
Release: 2023-09-04 19:45:03
forward
894 people have browsed it

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();
Copy after login

The syntax for date only.

SELECT CURDATE();
Copy after login

Let us now implement the above syntax −

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

mysql> SELECT NOW();
Copy after login

Output

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

Case 2: If you only want the current date -

mysql> SELECT CURDATE();
Copy after login

Output

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

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template