具有两位数年份的日期值是模糊的,因为世纪未知。这样的值必须解释为四位数形式,因为 MySQL 内部使用四位数字存储年份。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.
对于 DATETIME、DATE 和 TIMESTAMP 类型,MySQL 使用以下规则解释具有模糊年份值的日期:For DATETIME,
DATE, and
TIMESTAMP types, MySQL interprets
dates specified with ambiguous year values using these rules:
年份值在
00-69范围内时,将变为2000-2069。Year values in the range00-69become2000-2069.年份值在
70-99范围内时,将变为1970-1999。Year values in the range70-99become1970-1999.
对于 YEAR,规则相同,唯一区别是:将数字 00 插入 YEAR 会得到 0000 而不是 2000。要指定 YEAR 为零并将其解释为 2000,请将其指定为字符串 '0' 或 '00'。For YEAR, the rules are the same, with this
exception: A numeric 00 inserted into
YEAR results in 0000
rather than 2000. To specify zero for
YEAR and have it be interpreted as
2000, specify it as a string
'0' or '00'.
请记住,这些规则只是启发式方法,用于合理猜测您的数据值的含义。如果 MySQL 使用的规则未能产生您所需的值,您必须提供包含四位数年份的明确输入。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.
ORDER BY 可以正确排序具有两位数年份的 YEAR 值。ORDER BY properly sorts
YEAR values that have 2-digit
years.
像 MIN() 和 MAX() 这样的某些函数会将 YEAR 转换为数字。这意味着具有两位数年份的值在这些函数中不能正常工作。在这种情况下的解决方法是将 YEAR 转换为四位数年份格式。Some functions like MIN() and
MAX() convert a
YEAR to a number. 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.