setsql_mode='ALLOW_INVALID_DATES';QueryOK,0rowsaffected(0.00sec)"/> setsql_mode='ALLOW_INVALID_DATES';QueryOK,0rowsaffected(0.00sec)">

Home  >  Article  >  Database  >  What happens when MySQL encounters an out-of-range date?

What happens when MySQL encounters an out-of-range date?

WBOY
WBOYforward
2023-09-13 12:01:06610browse

当 MySQL 遇到超出范围的日期时会发生什么?

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete