Home  >  Article  >  Database  >  In MYSQL, how do we store a date with day, month or day both being zero and day being zero?

In MYSQL, how do we store a date with day, month or day both being zero and day being zero?

PHPz
PHPzforward
2023-08-27 14:25:101289browse

In MYSQL, how do we store a date with day, month or day both being zero and day being zero?

To store dates with day, month, or month and day all equal to zero, we must set the sql mode to allow_invalid_dates mode.

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

mysql> insert into check_date(OrderDate) values('2017-00-00');
Query OK, 1 row affected (0.06 sec)

mysql> select * from check_date;
+-------------+
| OrderDate |
+-------------+
| 2017-00-00 |
+-------------+
1 row in set (0.00 sec)

The above query will insert dates with both month and day values ​​being zero.

mysql> insert into check_date(Orderdate) values ('2017-00-05');
Query OK, 1 row affected (0.07 sec)

mysql> select * from check_date;
+------------+
| Orderdate  |
+------------+
| 2017-00-00 |
| 2017-00-05 |
+------------+
2 rows in set (0.00 sec)

The above query will insert dates with a month value of zero.

mysql> insert into check_date(Orderdate) values ('2017-05-00');
Query OK, 1 row affected (0.02 sec)

mysql> select * from check_date;
+------------+
| Orderdate  |
+------------+
| 2017-00-00 |
| 2017-00-05 |
| 2017-05-00 |
+------------+
3 rows in set (0.00 sec)

The above query will insert dates with a date value of zero.

The above is the detailed content of In MYSQL, how do we store a date with day, month or day both being zero and day being zero?. 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
Previous article:Audit trails in DBMSNext article:Audit trails in DBMS