11.2.4 The YEAR Type年份类型

The YEAR type is a 1-byte type used to represent year values. YEAR类型是用于表示年份值的1字节类型。It can be declared as YEAR with an implicit display width of 4 characters, or equivalently as YEAR(4) with an explicit display width.它可以声明为具有4个字符的隐式显示宽度的年份,或等效于具有显式显示宽度的YEAR(4)

Note注意

As of MySQL 8.0.19, the YEAR(4) data type with an explicit display width is deprecated and you should expect support for it to be removed in a future version of MySQL. 从MySQL8.0.19开始,带有显式显示宽度的YEAR(4)数据类型已被弃用,您应该期望在将来的MySQL版本中删除对它的支持。Instead, use YEAR without a display width, which has the same meaning.相反,使用不带显示宽度的YEAR,其含义相同。

MySQL 8.0 does not support the 2-digit YEAR(2) data type permitted in older versions of MySQL. MySQL 8.0不支持MySQL旧版本中允许的2位YEAR(2)数据类型。For instructions on converting to 4-digit YEAR, see 2-Digit YEAR(2) Limitations and Migrating to 4-Digit YEAR, in MySQL 5.7 Reference Manual.有关转换为4位数年份的说明,请参阅MySQL5.7参考手册中的2位数YEAR(2)限制和迁移到4位数YEAR

MySQL displays YEAR values in YYYY format, with a range of 1901 to 2155, and 0000.MySQL以YYYY格式显示YEAR值,范围为190121550000

YEAR accepts input values in a variety of formats:YEAR接受各种格式的输入值:

If strict SQL mode is not enabled, MySQL converts invalid YEAR values to 0000. 如果未启用严格SQL模式,MySQL会将无效的YEAR值转换为0000In strict SQL mode, attempting to insert an invalid YEAR value produces an error.在严格SQL模式下,尝试插入无效的YEAR值会产生错误。

See also Section 11.2.8, “2-Digit Years in Dates”.另见第11.2.8节,“日期中的两位数年份”