Current time when MySQL record is saved to database

后端 未结 3 1657
鱼传尺愫
鱼传尺愫 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());
    
    0 讨论(0)
  • 2021-01-29 13:23

    You can just define the column like:

    DATETIME DEFAULT CURRENT_TIMESTAMP
    
    0 讨论(0)
  • 2021-01-29 13:25

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

    0 讨论(0)
提交回复
热议问题