Home > Database > Mysql Tutorial > 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?

王林
Release: 2023-09-03 08:53:02
forward
956 people have browsed it

我们如何在 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)
Copy after login

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!

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