11.2.8 2-Digit Years in Dates日期中的两位数年份

Date values with 2-digit years are ambiguous because the century is unknown. 具有两位数年份的日期值不明确,因为世纪未知。Such values must be interpreted into 4-digit form because MySQL stores years internally using 4 digits.这些值必须被解释为4位数的形式,因为MySQL在内部使用4位数存储年份。

For DATETIME, DATE, and TIMESTAMP types, MySQL interprets dates specified with ambiguous year values using these rules:对于DATETIMEDATETIMESTAMP类型,MySQL使用以下规则解释使用不明确年份值指定的日期:

For YEAR, the rules are the same, with this exception: A numeric 00 inserted into YEAR results in 0000 rather than 2000. 对于YEAR,规则是相同的,但有一个例外:在年份中插入数字00,结果是0000而不是2000To specify zero for YEAR and have it be interpreted as 2000, specify it as a string '0' or '00'.若要为YEAR指定零并将其解释为2000,请将其指定为字符串'0''00'

Remember that these rules are only heuristics that provide reasonable guesses as to what your data values mean. 请记住,这些规则只是提供合理猜测数据值含义的启发式方法。If the rules used by MySQL do not produce the values you require, you must provide unambiguous input containing 4-digit year values.如果MySQL使用的规则没有生成所需的值,则必须提供包含4位年份值的明确输入。

ORDER BY properly sorts YEAR values that have 2-digit years.ORDER BY对具有两位数年份的年份值进行正确排序。

Some functions like MIN() and MAX() convert a YEAR to a number. 一些函数如MIN()MAX()YEAR转换为数字。This means that a value with a 2-digit year does not work properly with these functions. 这意味着具有两位数年份的值不能与这些函数一起正常工作。The fix in this case is to convert the YEAR to 4-digit year format.本例中的修复方法是将YEAR转换为4位数的年份格式。