Current time when MySQL record is saved to database

后端 未结 3 1659
鱼传尺愫
鱼传尺愫 2021-01-29 12:31

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

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-29 13:14

    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());
    

提交回复
热议问题