Current time when MySQL record is saved to database

断了今生、忘了曾经 提交于 2021-02-17 07:16:05

问题


I'm working with Zend Framework 1.12 and Mysql. I want to add column in database, which save currenct datetime when record was inserted into table.

Anyone knows how can I defined this column? This function must working on Mysql site, not PHP.


回答1:


you must change column type to TIMESTAMP , and in default field set CURRENT_TIMESTAMP




回答2:


There are different ways to do so.

You can define data type TIMESTAMP and set default value to CURRENT_TIMESTAMP

You can define column with data type datetime and use now() or sysdate() to get current date and time.

For eg.

 INSERT INTO `table_name`(current_time) VALUES(now());

or

 INSERT INTO `table_name`(current_time) VALUES(sysdate());



回答3:


You can just define the column like:

DATETIME DEFAULT CURRENT_TIMESTAMP


来源:https://stackoverflow.com/questions/34825361/current-time-when-mysql-record-is-saved-to-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!