MySQL让我很难更新时间戳列
mysql> describe payments;
+---------+------------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+-------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| user_id | int(10) unsigned | NO | | NULL | |
| cat_id | int(10) unsigned | NO | | NULL | |
| amount | int(11) | NO | | NULL | |
| time | timestamp | NO | | CURRENT_TIMESTAMP | |
+---------+------------------+------+-----+-------------------+----------------+
5 rows in set (0.00 sec)
我想将记录1的时间设置为2040年1月1日
mysql> select * from payments;
+----+---------+--------+--------+---------------------+
| id | user_id | cat_id | amount | time |
+----+---------+--------+--------+---------------------+
| 1 | 1 | 4 | 40 | 0000-00-00 00:00:00 |
| 2 | 1 | 3 | 30 | 2030-01-01 00:00:00 |
+----+---------+--------+--------+---------------------+
2 rows in set (0.00 sec)
但它给了我一个超出范围的警告
mysql> update payments set time='2040-01-01 00:00:00' where id=1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql> show warnings;
+---------+------+-----------------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------------+
| Warning | 1264 | Out of range value for column 'time' at row 1 |
+---------+------+-----------------------------------------------+
1 row in set (0.00 sec)
我错过了一些明显的东西吗?
答案 0 :(得分:3)
以下是您正在寻找的答案:
TIMESTAMP数据类型用于包含date和的值 时间部分。 TIMESTAMP的范围为' 1970-01-01 00:00:01' UTC到 ' 2038-01-19 03:14:07' UTC。
来源:http://dev.mysql.com/doc/refman/5.0/en/datetime.html
您尝试设置的日期为高。
答案 1 :(得分:2)
我认为您需要将列的数据类型从Timestamp
更改为Datetime
,而不是limitation of Timestamp to take the maximum data as '2038-01-19 03:14:07' UTC.。
答案 2 :(得分:1)