首页  >  文章  >  数据库  >  我们如何在 MySQL 中提供只有年(零个月和零天)值的日期?

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

王林
王林转载
2023-09-03 08:53:02913浏览

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

通过禁用 NO_ZERO_IN_DATE 模式,我们可以在 MySQL 表中存储仅包含年份值、零月份和零日的日期。如果启用此模式,MySQL 会将此类日期视为无效日期并存储全零。

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)

以上是我们如何在 MySQL 中提供只有年(零个月和零天)值的日期?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除