codehaven - php snippets - coding help
Generic filters
Exact matches only
  • Current Timestamp – on update/insert

    21st May 2014

    MySql

    mysql codehaven category

    If you want to record when an update happened to the file using timestamp, here’s the four simple steps you need to do.

    1. Create field to hold auto-updated timestamp (I call mine ‘updated’).
    2. Specify field Type as ‘TIMESTAMP’
    3. Specify field Default as ‘CURRENT_TIMESTAMP’
    4. Specify field Extra as ‘ON UPDATE CURRENT_TIMESTAMP’

    Now the field that contains your timestamp will always be updated to the current timestamp anytime the record is updated.

    If you miss step 4, this will only tell you when it was inserted.

    Was this code snippet helpful?