The YEAR
type is a 1-byte type used to represent year values. YEAR
类型是用于表示年份值的1字节类型。It can be declared as 它可以声明为具有4个字符的隐式显示宽度的年份,或等效于具有显式显示宽度的YEAR
with an implicit display width of 4 characters, or equivalently as YEAR(4)
with an explicit display width.YEAR(4)
。
As of MySQL 8.0.19, the 从MySQL8.0.19开始,带有显式显示宽度的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. 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 MySQL 8.0不支持MySQL旧版本中允许的2位YEAR(2)
data type permitted in older versions of MySQL. YEAR(2)
数据类型。For instructions on converting to 4-digit 有关转换为4位数年份的说明,请参阅MySQL5.7参考手册中的2位数YEAR
, see 2-Digit YEAR(2) Limitations and Migrating to 4-Digit YEAR, in MySQL 5.7 Reference Manual.YEAR(2)
限制和迁移到4位数YEAR
。
MySQL displays MySQL以YEAR
values in YYYY
format, with a range of 1901
to 2155
, and 0000
.YYYY
格式显示YEAR
值,范围为1901
到2155
和0000
。
YEAR
accepts input values in a variety of formats:YEAR
接受各种格式的输入值:
As 4-digit strings in the range '1901'
to '2155'
.'1901'
到'2155'
范围内的4位字符串。
As 4-digit numbers in the range 1901
to 2155
.1901
到2155
之间的4位数字。
As 1- or 2-digit strings in the range '0'
to '99'
. '0'
到'99'
范围内的1位或2位字符串。MySQL converts values in the ranges MySQL将范围为'0'
to '69'
and '70'
to '99'
to YEAR
values in the ranges 2000
to 2069
and 1970
to 1999
.'0'
到'69'
和'70'
到'99'
的值分别转换为范围为2000
到2069
和1970
到1999
的年份值。
As 1- or 2-digit numbers in the range 0
to 99
. 0
到99
之间的1位或2位数字。MySQL converts values in the ranges MySQL将1
to 69
and 70
to 99
to YEAR
values in the ranges 2001
to 2069
and 1970
to 1999
.1
到69
和70
到99
之间的值分别转换为2001
到2069
和1970
到1999
之间的年份值。
The result of inserting a numeric 插入数字0
has a display value of 0000
and an internal value of 0000
. 0
的结果的显示值为0000
,内部值为0000
。To insert zero and have it be interpreted as 若要插入零并将其解释为2000
, specify it as a string '0'
or '00'
.2000
,请将其指定为字符串'0'
或'00'
。
As the result of functions that return a value that is acceptable in 作为返回在YEAR
context, such as NOW()
.YEAR
上下文中可接受的值的函数的结果,例如NOW()
。
If strict SQL mode is not enabled, MySQL converts invalid 如果未启用严格SQL模式,MySQL会将无效的YEAR
values to 0000
. YEAR
值转换为0000
。In strict SQL mode, attempting to insert an invalid 在严格SQL模式下,尝试插入无效的YEAR
value produces an error.YEAR
值会产生错误。
See also Section 11.2.8, “2-Digit Years in Dates”.另见第11.2.8节,“日期中的两位数年份”。