Home > Database > Mysql Tutorial > body text

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

王林
Release: 2023-08-24 13:33:05
forward
1004 people have browsed it

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

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

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!

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