借助CURDATE()
和NOW()
函数,我们可以自动将当前日期插入MySQL表的列中。
假设我们要在表year_test的OrderDate列中自动插入当前日期,下面的查询将执行此操作-
mysql> Insert into year_testing (OrderDate) Values(CURDATE()); mysql> Select * from year_testing; +------------+ | OrderDate | +------------+ | 2017-10-28 | +------------+ 1 row in set (0.00 sec) mysql> Insert into year_testing (OrderDate) Values(NOW()); mysql> Select * from year_testing; +------------+ | OrderDate | +------------+ | 2017-10-28 | | 2017-10-28 | +------------+ 2 rows in set (0.00 sec)