Home > Database > Mysql Tutorial > How to automatically insert current date in column of MySQL table?

How to automatically insert current date in column of MySQL table?

WBOY
Release: 2023-08-24 10:41:07
forward
1207 people have browsed it

如何在 MySQL 表的列中自动插入当前日期?

With the help of CURDATE() and NOW() functions, we can automatically insert the current date into the columns of the MySQL table.

Example

Suppose we want to automatically insert the current date in the OrderDate column of table year_testing, the following query will do this -

mysql> Insert into year_testing (OrderDate) Values(CURDATE());
Query OK, 1 row affected (0.11 sec)
mysql> Select * from year_testing;
+------------+
| OrderDate  |
+------------+
| 2017-10-28 |
+------------+
1 row in set (0.00 sec)

mysql> Insert into year_testing (OrderDate) Values(NOW());
Query OK, 1 row affected, 1 warning (0.12 sec)

mysql> Select * from year_testing;
+------------+
| OrderDate  |
+------------+
| 2017-10-28 |
| 2017-10-28 |
+------------+
2 rows in set (0.00 sec)
Copy after login

The above is the detailed content of How to automatically insert current date in column of MySQL table?. 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