问题
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