【问题标题】:MySQL incorrect datetime value error for valid dates有效日期的 MySQL 不正确的日期时间值错误
【发布时间】:2019-04-11 14:36:37
【问题描述】:

我有一个时间戳列,当我尝试输入某些特定日期和时间时出现错误。

例如 2013-03-31 02:13:112014-03-31 02:55:00 工作,但 2013-03-31 02:55:00 说:

SQL Error (1292): Incorrect datetime value

可能是什么问题?

【问题讨论】:

  • 确保周围没有任何特殊字符。
  • 是 - 日期和时间之间是一个特殊字符
  • 所以我在谷歌上搜索,发现罗马尼亚 2013 年的夏令时从 3 月 31 日星期日凌晨 3:00 开始。会不会是这个问题?
  • 我没有任何特殊字符。我只是在 HeidiSQL 中手动编辑它。
  • @SalmanA 这是有道理的。我想这可能是原因。

标签: mysql datetime timestamp


【解决方案1】:

这可能是夏令时问题,尤其是当您提到导致问题的日期是 2013-03-31 02:55:00...大多数欧洲国家/地区开始观察 2013 年 DST 的日期时。中欧时间提前了凌晨 2 点的小时,这意味着那天没有 02:55:00

请注意,MySQL 将 TIMESTAMP 值从当前时区转换为 UTC 进行存储,这就是引发错误的地方:

SET time_zone = 'CET';
-- Central Europe Time in 2013: DST starts at 2am when clocks move forward to 3am
-- see https://www.timeanddate.com/news/time/europe-starts-dst-2013.html

INSERT INTO test(timestamp_col) VALUES('2013-03-31 01:59:59');
-- Affected rows: 1  Found rows: 0  Warnings: 0  Duration for 1 query: 0.078 sec.

INSERT INTO test(timestamp_col) VALUES('2013-03-31 02:00:00');
-- SQL Error (1292): Incorrect datetime value: '2013-03-31 02:00:00' for column 'timestamp_col' at row 1

INSERT INTO test(timestamp_col) VALUES('2013-03-31 03:00:00');
-- Affected rows: 1  Found rows: 0  Warnings: 0  Duration for 1 query: 0.063 sec.

【讨论】:

  • 这有点道理。但奇怪的是 2:13 有效,而 2:55 无效。
猜你喜欢
  • 2014-06-28
  • 2023-04-02
  • 2017-08-26
  • 2020-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多