MySQL: trying to insert value in timestamp causes an error

I have a table with this column:

last_modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

And it looks like I cannot insert a line with a custom timestamp, I get this error:

Invalid date and time value: '1145868501' for last_modified column in row 1

I am trying to populate this table with data coming from another table, that there is a create_time field in the other table, which is DATETIME, so I use UNIX_TIMESTAMP (creation_time) to populate the timestamp.

I think the timestamp column with "DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" does not allow me to insert my own things, right? If so, where is the official document on this and what is the best solution? First create a simple timestamp, and then change the table after inserting the data?

Thank!

EDIT: since people advise me not to use UNIX_TIMESTAMP, I have to say that I did not want to use this at the beginning, but I got this error: Invalid date and time value: '2010-03-28 02:15:51' for the column 'last_modified' So I thought I needed to insert a “real” timestamp ...

+5
source share
3 answers

TIMESTAMP. : TIMESTAMP

TIMESTAMP, , , . , TIMESTAMP . , TIMESTAMP , NULL.


-, - , - '2010-03-28 02:15:51'! ( , 02:00 - 03:00 03:00 - 04:00.

: .

+2

datetime. . UNIX_TIMESTAMP(), .

MySQL TIMESTAMP DATETIME; . SELECT UPDATE, DATETIME.

+1

If the column is always automatically updated, you can remove the property, getters and setters from the entity. However, it will be ignored in all requests.

0
source

All Articles