4
I would like to know the time a record was added to the bank. I will use this information to show the time a contact was added to my schedule.
4
I would like to know the time a record was added to the bank. I will use this information to show the time a contact was added to my schedule.
4
Create a column of type TIMESTAMP.
In the 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
4
In the skywalker’s response, indicated the path to place a column in the database with the type TIMESTAMP
and with DEFAULT CURRENT_TIMESTAMP
.
Meanwhile, the guy TIMESTAMP
suffers from the bug of the year 2038. That way, his replacement would be the guy DATETIME
. This works from version 5.6 of Mysql.
For previous versions, the DATETIME
cannot be used with DEFAULT CURRENT_TIMESTAMP
. In this case, there are two possible solutions:
Drop out DEFAULT
and explicitly inform you whenever a INSERT
is realized.
Use a TRIGGER
, as suggested in this reply by Soen.
Browser other questions tagged java sql database
You are not signed in. Login or sign up in order to post.
Does this column automatically save the time it was added? Or do I have to implement this in my code and insert it into the database?
– Bruno Brito
which database you are using?
– Skywalker
Mysql, in the xampp.
– Bruno Brito
Beware of the year 2038 bug. The
TIMESTAMP
data type is used for values that contain Both date and time Parts.TIMESTAMP
has a range of '1970-01-01 00:00:01
' UTC to '2038-01-19 03:14:07
' UTC. CC @Brunobrito– Victor Stafusa
Is there another way to do it? @Victorstafusa
– Bruno Brito