MySQL's response when an out-of-range or invalid date is encountered will depend on the SQL MODE. If we enable ALLOW_INVALID_DATES mode, then MySQL will convert out-of-range values to all zeros (i.e. "0000:00:00 00:00:00") and store them in the table without generating any errors or warnings . p>
For example, we can change the SQL MODE as follows and then insert out-of-range content -
mysql> set sql_mode = 'ALLOW_INVALID_DATES'; Query OK, 0 rows affected (0.00 sec) mysql> Insert into order1234(productname, quantity, orderdate) values('A', 500, '999-05-100'); Query OK, 1 row affected, 1 warning (0.13 sec) mysql> Select * from order1234; +-------------+----------+---------------+ | ProductName | Quantity | OrderDate | +-------------+----------+---------------+ | A | 500 | 0000-00-00 | +-------------+----------+---------------+ 1 row in set (0.00 sec)
We can see that MySQL converts out-of-range values to all zeros.
The above is the detailed content of What happens when MySQL encounters an out-of-range date?. For more information, please follow other related articles on the PHP Chinese website!