SETsql_mode='allow_invalid_dates';QueryOK,0rowsaffected,1warning(0.03sec)mysql>Createtabletest_date(date_orderdate);QueryOK,0rowsaffected(0.45sec"/> SETsql_mode='allow_invalid_dates';QueryOK,0rowsaffected,1warning(0.03sec)mysql>Createtabletest_date(date_orderdate);QueryOK,0rowsaffected(0.45sec">

Home  >  Article  >  Database  >  How to store "0000-00-00" as a date in MySQL?

How to store "0000-00-00" as a date in MySQL?

王林
王林forward
2023-09-07 13:25:02973browse

如何在 MySQL 中将“0000-00-00”存储为日期?

In order to store a date like "0000-00-00" in a column of a MySQL table, we have to set the SQL mode to "allow_invalid_date". The following example will demonstrate it -

mysql> SET sql_mode = 'allow_invalid_dates';
Query OK, 0 rows affected, 1 warning (0.03 sec)

mysql> Create table test_date(date_order date);
Query OK, 0 rows affected (0.45 sec)

mysql> Insert into test_date(date_order) values('0000-00-00');
Query OK, 1 row affected (0.04 sec)

mysql> Select * from test_date;
+------------+
| date_order |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)

The above is the detailed content of How to store "0000-00-00" as a date in MySQL?. 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