Home  >  Article  >  Database  >  How can we provide a date with only year (zero months and zero days) value in MySQL?

How can we provide a date with only year (zero months and zero days) value in MySQL?

王林
王林forward
2023-09-03 08:53:02912browse

我们如何在 MySQL 中提供只有年(零个月和零天)值的日期?

By disabling the NO_ZERO_IN_DATE mode, we can store dates in MySQL tables that only contain year values, zero months, and zero days. If this mode is enabled, MySQL treats such dates as invalid dates and stores all zeros.

mysql> Insert into year_testing (OrderDate) values('2017:00:00');
Query OK, 1 row affected (0.09 sec)

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

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

mysql> Insert into year_testing(OrderDate) values('2017:00:00');
Query OK, 1 row affected, 1 warning (0.04 sec)

mysql> Select * year_testing;
+------------+
| OrderDate  |
+------------+
| 2017-00-00 |
| 0000-00-00 |
+------------+
1 rows in set (0.00 sec)

The above is the detailed content of How can we provide a date with only year (zero months and zero days) value 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