我有一个 TIMESTAMP
字段,但它不接受值 2014-10-19 00:00:00
。
我使用的是 MySQL 5.6,并且我在 Windows 和 Linux 版本中都进行了测试。
如果第一种格式不被接受,我应该写什么?
最佳答案
create table thing9
( id int auto_increment primary key,
theWhat varchar(80) not null,
theWhen timestamp not null
);
insert thing9(theWhat,theWhen) values('fish','2014-10-19 00:00:00');
insert thing9(theWhat,theWhen) values('fish','2012-10-19 00:00:00');
insert thing9(theWhat,theWhen) values('fish','2016-10-19 00:00:00');
update thing9 set theWhen='2011-10-19 00:00:00' where id=2;
+----+---------+---------------------+
| id | theWhat | theWhen |
+----+---------+---------------------+
| 1 | fish | 2014-10-19 00:00:00 |
| 2 | fish | 2011-10-19 00:00:00 |
| 3 | fish | 2016-10-19 00:00:00 |
+----+---------+---------------------+
mysql> show variables like '%versi%';
+-------------------------+------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------+
| innodb_version | 5.6.24 |
| protocol_version | 10 |
| slave_type_conversions | |
| version | 5.6.24-log |
| version_comment | MySQL Community Server (GPL) |
| version_compile_machine | x86_64 |
| version_compile_os | Win64 |
+-------------------------+------------------------------+
编辑:
我想知道您是否有 mysql 时区的问题。请查看Mysql手册页链接here ,下面是其中的一小段摘录。
mysql> SELECT @@global.time_zone, @@session.time_zone; timezone values can be given in several formats, none of which are case sensitive:
The value 'SYSTEM' indicates that the time zone should be the same as the system time zone.
The value can be given as a string indicating an offset from UTC, such as '+10:00' or '-6:00'.
编辑2:
show variables where variable_name like '%datetime%'
+-----------------+-------------------+
| Variable_name | Value |
+-----------------+-------------------+
| datetime_format | %Y-%m-%d %H:%i:%s |
+-----------------+-------------------+
如果您的顺序是 D-M-Y 或其他顺序,请根据情况进行更改。
关于MySQL 无法使用 '2014-10-19 00:00:00' 更新 TIMESTAMP 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32156795/