Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL incorrect DATETIME format

I have an app with Doctrine 1 and I generate update_datetime fields for objects via new Zend_Date->getIso(). It worked just fine for years, but now I got a new notebook and Doctrine tries to insert a DATETIME fields as a string "2013-07-12T03:00:00+07:00" instead of normal MySQL datetime format "2013-07-12 00:00:00" which is totally weird.

The very same code runs just fine on another computer. Everything is nearly identical – MySQL 5.6.12, PHP 5.3.15 on both. Any idea where should I look?

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

UPDATE

Ok with the help from StackOverflow community I finally solved it. The problem was with STRICT_TRANS_TABLES in sql_mode variable. But changing it in /etc/my.cnf seemed not enough, so I had to run mysql -uroot and type the following:

set sql_mode=NO_ENGINE_SUBSTITUTION; set global sql_mode=NO_ENGINE_SUBSTITUTION;

Thus removing STRICT_TRANS_TABLES

UPDATE2 How to get rid of STRICT forever? How to get rid of STRICT SQL mode in MySQL

like image 361
firedev Avatar asked Jul 11 '13 16:07

firedev


People also ask

What is the format of DATETIME in MySQL?

MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

How do I insert date in YYYY-MM-DD format in MySQL?

MySQL comes with the following data types for storing a date or a date/time value in the database: DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: YYYY-MM-DD HH:MI:SS.

What data type to use for date in MySQL?

MySQL comes with the following data types for storing a date or a date/time value in the database: DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: YYYY-MM-DD HH:MI:SS.

What is TIMESTAMP format in SQL?

SQL Date Data Types For storing date and time, the different data types are: DATE – in YYYY-MM-DD format in SQL. YEAR – in YYYY or YY format in SQL. TIMESTAMP – in YYYY-MM-DD HH: MI:SS format in SQL. DATETIME – in YYYY-MM-DD HH: MI: SS format in SQL.


2 Answers

If it exists, you can try removing STRICT_TRANS_TABLES from sql-mode in your my.ini.

This can cause this error with a datetime string value containing the format you have not being converted to mysql datetime. This my.ini change was reported as a fix in:

like image 61
hakre Avatar answered Oct 23 '22 13:10

hakre


Date constants in zend are determined from sniffing out locale in this order (form zend_locale comments)

1. Given Locale
2. HTTP Client
3. Server Environment
4. Framework Standard

I'm thinking the difference between the two systems is going to be reflected in the Server Environment.

To correct and avoid this problem in the future you can specify the locale options within your application.ini using these configuration directive.

resources.locale.default = <DEFAULT_LOCALE>
resources.locale.force = false
resources.locale.registry_key = "Zend_Locale"

The locale should be set to a string like en_US

Zend_Locale specificly sniffs the locale from the environment from a call to setlocale and parsing the results.

like image 2
Orangepill Avatar answered Oct 23 '22 12:10

Orangepill