DATETIME
, DATE
, and TIMESTAMP
Types
TIME
Type
YEAR
Type
MySQL itself is Y2K-safe (see section 1.2.5 Year 2000 Compliance), but input values presented to MySQL may not be. Any input containing 2-digit year values is ambiguous, because the century is unknown. Such values must be interpreted into 4-digit form because MySQL stores years internally using four digits.
For DATETIME
, DATE
, TIMESTAMP
, and YEAR
types,
MySQL interprets dates with ambiguous year values using the
following rules:
00-69
are converted to 2000-2069
.
70-99
are converted to 1970-1999
.
Remember that these rules provide only reasonable guesses as to what your data mean. If the heuristics used by MySQL don't produce the correct values, you should provide unambiguous input containing 4-digit year values.
ORDER BY
will sort 2-digit YEAR/DATE/DATETIME
types properly.
Note also that some functions like MIN()
and MAX()
will convert a
TIMESTAMP/DATE
to a number. This means that a timestamp with a
2-digit year will not work properly with these functions. The fix in this
case is to convert the TIMESTAMP/DATE
to 4-digit year format or
use something like MIN(DATE_ADD(timestamp,INTERVAL 0 DAYS))
.