简体   繁体   中英

Mysql accepts Zero month in date column!? Please explain

MySQL 5.6 - we had a talk with one of the developers and found something very curious - couldn't find anything about it in google:

create temporary table md (dates date);
insert into md select '2000-01-01'; -- result: 2000-01-01
insert into md select '2000-00-01'; -- result: 1999-12-01 ????
insert into md select '2000-00-00'; -- result: 1999-11-30 ????
insert into md select '2000-01-00'; -- result: 1999-12-31 ????
insert into md select '2000-13-01'; -- result: EXPECTED: SQL Error [1292] [22001]: Data truncation: Incorrect date value: '2000-13-01' for column 'dates' at row 1
insert into md select '2000-12-49'; -- result: EXPECTED: SQL Error [1292] [22001]: Data truncation: Incorrect date value: '2000-12-49' for column 'dates' at row 1

Could someone please explain?

  1. Why does it let this happen? It should throw the same Data issue error imho.
  2. Documentation?
  3. What is the exact logic behind this?

    a) Month 00 previous month same day?

    b) Day 00 previous month last day?

    c) both 00-00 previous month's previous' last day?

Thanks!

https://dev.mysql.com/doc/refman/8.0/en/using-date.html

MySQL permits you to store dates where the day or month and day are zero. This is convenient if you want to store a birthdate in a DATE column and you know only part of the date. To disallow zero month or day parts in dates, enable the NO_ZERO_IN_DATE mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM