Home  >  Article  >  Database  >  How to store a date like February 30th in a MySQL date column?

How to store a date like February 30th in a MySQL date column?

王林
王林forward
2023-08-24 13:33:05977browse

How to store a date like February 30th in a MySQL date column?

Suppose we want to store a date such as February 30th in a MySQL table, then we must first enable ALLOW_INVALID_DATES mode.

For example, if I try to add such a date in the table without enabling ALLOW_INVALID_DATES mode, MySQL will give the following error message:

mysql> Insert into date_testing(date) values('2017-02-30');
ERROR 1292 (22007): Incorrect date value: '2017-02-30' for column
'Date' at row1

Now we need to enable ALLOW_INVALID_DATES mode as follows −

mysql> SET sql_mode = 'ALLOW_INVALID_DATES';
Query OK, 0 rows affected (0.00 sec)

mysql> Insert into date_testing(date) values('2017-02-30');
Query OK, 1 row affected (0.14 sec)

mysql> select * from date_testing;
+------------+
| Date |
+------------+
| 2017-02-30 |
+------------+
1 row in set (0.00 sec)

The above MySQL query will allow us to insert such invalid dates in the column.

The above is the detailed content of How to store a date like February 30th in a MySQL date column?. 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