我们如何在MySQL中提供仅包含年份(零个月零天)值的日期?
通过禁用NO_ZERO_IN_DATE模式,我们可以在MySQL表中存储仅包含年份值且具有零个月和零天的日期。如果启用此模式,则MySQL会将此类日期视为无效日期,并存储所有零。
mysql> Insert into year_testing (OrderDate) values('2017:00:00');
mysql> select * from year_testing;
+------------+
| OrderDate |
+------------+
| 2017-00-00 |
+------------+
1 row in set (0.00 sec)
mysql> SET sql_mode = 'NO_ZERO_IN_DATE';
mysql> Insert into year_testing(OrderDate) values('2017:00:00');
mysql> Select * year_testing;
+------------+
| OrderDate |
+------------+
| 2017-00-00 |
| 0000-00-00 |
+------------+
1 rows in set (0.00 sec)