Reputation: 48001
I want to store the timestamp which a row was inserted into a MySQL table with the row, to be later compared to other times. What's the best field type for this and what's the best way to insert the row with the timestamp in PHP?
Upvotes: 4
Views: 3213
Reputation: 798546
Use TIMESTAMP DEFAULT CURRENT_TIMESTAMP
. This will create a TIMESTAMP field that is set on INSERT, but not on UPDATE.
Upvotes: 5
Reputation: 21828
Use TIMESTAMP as the field type. All TIMESTAMP field types will have CURRENT_TIMESTAMP as the default (which is a alias for NOW())
While adding a record, write ''
to that field - it will take the default time as the value.
Upvotes: 1
Reputation: 26993
Use the DateTime datatype for the column, the NOW() function to set the current time and the UNIX_TIMESTAMP() function if you need to compare it using PHP
Upvotes: 0