diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index 756deab80e0..fcadba016fa 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -102,3 +102,13 @@ insert into t1 values (now(), now()); select * from t1 where a is null or b is null; a b drop table t1; +create table t1 (dt datetime); +insert into t1 values ("12-00-00"), ("00-00-00 01:00:00"); +insert into t1 values ("00-00-00"), ("00-00-00 00:00:00"); +select * from t1; +dt +2012-00-00 00:00:00 +2000-00-00 01:00:00 +0000-00-00 00:00:00 +0000-00-00 00:00:00 +drop table t1; diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index 850e5238111..a7f9004d062 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -68,3 +68,15 @@ insert into t1 values (now(), now()); insert into t1 values (now(), now()); select * from t1 where a is null or b is null; drop table t1; + +# +# Test for bug #7297 "Two digit year should be interpreted correctly even +# with zero month and day" +# +create table t1 (dt datetime); +# These dates should be treated as dates in 21st century +insert into t1 values ("12-00-00"), ("00-00-00 01:00:00"); +# Zero dates are still special :/ +insert into t1 values ("00-00-00"), ("00-00-00 00:00:00"); +select * from t1; +drop table t1; diff --git a/sql/time.cc b/sql/time.cc index 38670db054f..d8b4b80e351 100644 --- a/sql/time.cc +++ b/sql/time.cc @@ -410,7 +410,7 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date) else date[6]=0; - if (year_length == 2 && i >=2 && (date[1] || date[2])) + if (year_length == 2 && not_zero_date) date[0]+= (date[0] < YY_PART_YEAR ? 2000 : 1900); number_of_fields=i; while (i < 6)