How to save time created in MySQL table?

I want to save the timestamp in which the row was inserted into the MySQL table with the row, in order to later compare it with others. What is the best type of field for this and what is the best way to insert a timestamp string in PHP?

+4
source share
4 answers

Use TIMESTAMP DEFAULT CURRENT_TIMESTAMP . This will create a TIMESTAMP field that will be set to INSERT, but not to UPDATE.

+5
source

Use TIMESTAMP as the field type. All TIMESTAMP field types will have CURRENT_TIMESTAMP as the default value (which is an alias for NOW ())

When adding an entry, write '' in this field - this will take the default time as the value.

+1
source

Use TIMESTAMP NOT NULL

When you execute INSERT and leave this column, the default will be CURRENT_TIMESTAMP

0
source

Use the DateTime data type for the NOW () column to set the current time and the UNIX_TIMESTAMP () function if you need to compare it using PHP

0
source

All Articles