Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2023-09-13 12:01:06
forward
609 people have browsed it

当 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template