- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we provide a date with only year (zero months & zero days) value in MySQL?
We can store a date with only year value and have zero months as well as zero-days in MySQL table by disabling NO_ZERO_IN_DATE mode. If this mode is enabled then MySQL will count such kind of date as invalid date 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)
Advertisements