Description:
Prompted by bug #23653.
MySQL isn't consistent in how the zero date is handled by date functions.
How to repeat:
See attachment for test case.
Suggested fix:
These results are wrong:
-- This is bug #23653
LAST_DAY('0000-00-00 00:00:00')
0000-00-58
EXTRACT(WEEK FROM '0000-00-00 00:00:00')
613462402
I'm not sure if we should allow this, or return NULL as with other
TIMEDIFF results:
TIMEDIFF('0000-00-00 00:00:00', '0000-00-00 00:00:00')
00:00:00
I think these should be NULL, not 0:
QUARTER('0000-00-00 00:00:00')
0
EXTRACT(QUARTER FROM '0000-00-00 00:00:00')
0
For DATE_FORMAT, I'll comment on each format separately.
These are probably OK:
DATE_FORMAT('0000-00-00 00:00:00', '%c')
0
-- Not positive about this one
DATE_FORMAT('0000-00-00 00:00:00', '%D')
0th
DATE_FORMAT('0000-00-00 00:00:00', '%d')
00
DATE_FORMAT('0000-00-00 00:00:00', '%e')
0
DATE_FORMAT('0000-00-00 00:00:00', '%m')
00
DATE_FORMAT('0000-00-00 00:00:00', '%Y')
0000
DATE_FORMAT('0000-00-00 00:00:00', '%y')
00
These should be NULL:
DATE_FORMAT('0000-00-00 00:00:00', '%a')
Sat
DATE_FORMAT('0000-00-00 00:00:00', '%j')
4294236812
DATE_FORMAT('0000-00-00 00:00:00', '%U')
613462402
DATE_FORMAT('0000-00-00 00:00:00', '%u')
613462402
DATE_FORMAT('0000-00-00 00:00:00', '%V')
01
DATE_FORMAT('0000-00-00 00:00:00', '%v')
613462402
DATE_FORMAT('0000-00-00 00:00:00', '%W')
Saturday
DATE_FORMAT('0000-00-00 00:00:00', '%w')
6
DATE_FORMAT('0000-00-00 00:00:00', '%X')
0001
DATE_FORMAT('0000-00-00 00:00:00', '%x')
0000
I guess the TIME formats are OK returning 0, but it would be cleaner to
return NULL for them. It seems wrong to return 12 for %h, for example;
yet, why return NULL for %h, but not for %H? They are:
DATE_FORMAT('0000-00-00 00:00:00', '%f')
000000
DATE_FORMAT('0000-00-00 00:00:00', '%H')
00
DATE_FORMAT('0000-00-00 00:00:00', '%h')
12
DATE_FORMAT('0000-00-00 00:00:00', '%I')
12
DATE_FORMAT('0000-00-00 00:00:00', '%i')
00
DATE_FORMAT('0000-00-00 00:00:00', '%k')
0
DATE_FORMAT('0000-00-00 00:00:00', '%l')
12
DATE_FORMAT('0000-00-00 00:00:00', '%p')
AM
DATE_FORMAT('0000-00-00 00:00:00', '%r')
12:00:00 AM
DATE_FORMAT('0000-00-00 00:00:00', '%S')
00
DATE_FORMAT('0000-00-00 00:00:00', '%s')
00
DATE_FORMAT('0000-00-00 00:00:00', '%T')
00:00:00
These are missing a Warning:
DATE_FORMAT('0000-00-00 00:00:00', '%b')
NULL
DATE_FORMAT('0000-00-00 00:00:00', '%M')
NULL
These results are missing a Warning:
ADDTIME('0000-00-00 00:00:00', '00:00:00')
NULL
ADDTIME('0000-00-00 00:00:00', '01:02:03')
NULL
MONTHNAME('0000-00-00 00:00:00')
NULL
SUBTIME('0000-00-00 00:00:00', '00:00:00')
NULL
SUBTIME('0000-00-00 00:00:00', '01:02:03')
NULL
TIMEDIFF('0000-00-00 00:00:00', '1981-02-03 04:05:06')
NULL
TIMEDIFF('1981-02-03 04:05:06', '0000-00-00 00:00:00')
NULL
TIMESTAMP('0000-00-00 00:00:00', '00:00:00')
NULL
TIMESTAMP('0000-00-00 00:00:00', '01:02:03')
NULL