I would like to know the time a record was added to the bank. I'll use this information to show the time a contact was added to my calendar.
I would like to know the time a record was added to the bank. I'll use this information to show the time a contact was added to my calendar.
Create a column of type TIMESTAMP .
In MySQL , to save date and time automatically when adding some item just create the table as follows.
CREATE TABLE t1 (
data_criado TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
SOURCE: MySQL Documentation
In Skywalker's response , the way to place a column in the database with the type was indicated TIMESTAMP
and DEFAULT CURRENT_TIMESTAMP
.
However, type TIMESTAMP
suffers with the year 2038 bug . In this way, the substitute for it would be DATETIME
type. This works from version 5.6 of MySQL.
For previous versions, DATETIME
can not be used with DEFAULT CURRENT_TIMESTAMP
. In this case, there are two possible solutions:
Abandon the DEFAULT
value and explicitly inform it whenever a INSERT
is performed.
Use TRIGGER
, as suggested in this SOen response .