Home > Database > Mysql Tutorial > 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
Release: 2023-08-27 14:25:10
forward
1362 people have browsed it

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

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

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

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!

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