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!