Меню Закрыть

Mysql incorrect datetime value

I am getting this error when I try to insert ‘2011/03/13 02:53:50.000000000’ into a timestamp column. If I change the 13 to a 15, 14, 12 or 11 it works no problem. I’ve also tried changing the /’s to -‘s and still no-go.

I’ve looked through some of the other threads related to this error but none seem to apply.

I’m running version 5.7.9.

4 Answers 4

It took me a while to figure this out.

The problem is that ‘2011-03-13 02:53:50’ is illegal because of daylight saving time switch between 2 and 3 AM, so all time values between 2 and 3 am on any DST introduction day are invalid. Same for ‘2016-03-13 02:32:21’, etc.

Change the system timezone to the one that does not use DST and you should be fine.

You need to try this:

or else you have to insert the dates using the dash seperator (-) like

I think you need to use some str conversions in MySQL before inserting. Or to prepare the data in the proper format, before making the query to MySQL.

A DATETIME or TIMESTAMP value can include a trailing fractional seconds part in up to microseconds (6 digits) precision.

UPDATE: on my localhost I’ve got the same version of MySQL, and it works. Tryed to execute conversion

Here’s the SQLFiddle, that confirms the thing on other version of MySQL.

I run out of ideas, I think the issue is connected to the "local glitch" in Table structure or specific version of MySQL+OS.

I’m using MySQL 5.6 and I have a program that runs the following SQL statement against my database:

Читайте также:  Аналог риталина в россии

Unforutnately, I get the following error: Incorrect datetime value: ‘2013-08-25T17:00:00+00:00’ for column ‘s_time’ at row 1

The datatype for s_time is DateTime.

I have already attempted to set the allow_invalid_dates property using the workbench.

Can anyone understand and please explain this error to me? I know that if I manually change the statement to UPDATE m_table SET s_time = ‘2013-08-25 17:00:00’ WHERE , the statement works.

Unfortunately, I cannot modify the program that supplies the SQL statement (which I’m told is valid by the creator of the program) and I also cannot understand what the +00:00 symbolises.

migrated from serverfault.com Aug 25 ’13 at 22:45

This question came from our site for system and network administrators.

1 Answer 1

This is a valid iso-8601 datetime value, but it is not a valid MySQL datetime literal. On that point, the developer is incorrect.

The documentation explains what ALLOW_INVALID_DATES does:

Check only that the month is in the range from 1 to 12 and the day is in the range from 1 to 31.

In other words, 2013-02-31 would be a permissible date if allow_invalid_dates is set. This option does not do anything when the date or datetime isn’t even in a valid format for MySQL.

The +00:00 is the timezone offset from UTC. In this case, the time expressed is in UTC, so the offset is zero hours, zero minutes.

Your workaround would be to remove the STRICT_TRANS_TABLES from the sql_mode that is a default in the config file created during the MySQL 5.6 installation process. you need to carefully consider the implications of changing this, but it does allow the data to go in.

Читайте также:  Засохли картриджи hp что делать

У меня есть приложение с Doctrine 1, и я генерирую поля update_datetime для объектов через new Zend_Date->getIso() . В течение многих лет он работал отлично, но теперь у меня появился новый блокнот, и Doctrine пытается вставить поля DATETIME в виде строки "2013-07-12T03:00:00+07:00" вместо обычного формата даты и времени MySQL "2013-07-12 00:00:00" что совершенно странно.

Тот же самый код отлично работает на другом компьютере. Все почти идентично – MySQL 5.6.12, PHP 5.3.15 на обоих. Любая идея, где я должен смотреть?

Fatal error: Uncaught exception ‘Doctrine_Connection_Mysql_Exception’ with message ‘SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: ‘2013-07-12T03:00:00+07:00’ for column ‘nextrun’ at row 1′ in library/Doctrine/Connection.php:1083

ОБНОВИТЬ

Хорошо с помощью сообщества StackOverflow, я, наконец, решил это. Проблема была в sql_mode переменной sql_mode . Но изменить его в /etc/my.cnf оказалось недостаточно, поэтому мне пришлось запустить mysql -uroot и ввести следующее:

set sql_mode=NO_ENGINE_SUBSTITUTION; set global sql_mode=NO_ENGINE_SUBSTITUTION;

Таким образом, удаление STRICT_TRANS_TABLES

UPDATE2 Как избавиться от STRICT навсегда? Как избавиться от режима STRICT SQL в MySQL

Если он существует, вы можете попробовать удалить STRICT_TRANS_TABLES из sql-mode в my.ini.

Это может привести к этой ошибке со строковым значением datetime, содержащим формат, который вы не преобразовали в mysql datetime. Это изменение my.ini было сообщено как исправление в:

  • PING вызывает 500 Internal Server Error – неправильное значение даты и времени (ошибка AuthPuppy # 907203)

Константы даты в zend определяются исходя из локализации в этом порядке (форма zend_locale comments)

Я думаю, что разница между этими двумя системами будет отражена в серверной среде.

Чтобы исправить и избежать этой проблемы в будущем, вы можете указать параметры локали в своем приложении application.ini, используя эту конфигурационную директиву.

Читайте также:  Bsvcprocessor вылазиет на рабочем столе как убрать

Локаль должен быть установлен в строку, такую ​​как en_US

Zend_Locale специфически нюхает локаль из среды от вызова setlocale и анализирует результаты.

Это вызвано тем, что Zend не устанавливает формат timestamp в соответствие с тем, что ожидает MySQL. Вы можете отключить режим STRICT в MySQL, но это взлом, а не решение (MySQL будет пытаться угадать, какая дата вы входите).

В Zend вы можете установить формат datetime для того, что MySQL ожидает решить:

Хорошо с помощью сообщества StackOverflow, я, наконец, решил это. Проблема была в STRICT_TRANS_TABLES в переменной sql_mode. Но изменить его в /etc/my.cnf оказалось недостаточно, поэтому мне пришлось запустить mysql -uroot и ввести следующее:

set sql_mode = NO_ENGINE_SUBSTITUTION; установить глобальный sql_mode = NO_ENGINE_SUBSTITUTION;

Таким образом, удаление STRICT_TRANS_TABLES

Рекомендуем к прочтению

Добавить комментарий

Ваш адрес email не будет опубликован.