Spec-Zone .ru
спецификации, руководства, описания, API
|
The YEAR
type is a 1-byte type used to represent year values. It can be declared as
YEAR(4)
or YEAR(2)
to specify a display width of four
or two characters. The default is four characters if no width is given.
The YEAR(2)
data type has certain issues that you should consider
before choosing to use it. Also, as of MySQL 5.6.6, YEAR(2)
is deprecated.
YEAR(2)
columns in existing tables are treated as before, but YEAR(2)
in new or altered tables are converted to YEAR(4)
.
For more information, see Section 11.3.4,
"YEAR(2)
Limitations and Migrating to YEAR(4)
".
YEAR(4)
and YEAR(2)
differ in display format, but have
the same range of values. For 4-digit format, MySQL displays YEAR
values in YYYY
format, with a range of 1901
to 2155
, or 0000
. For 2-digit format, MySQL displays
only the last two (least significant) digits; for example, 70
(1970 or 2070) or
69
(2069).
You can specify input YEAR
values in a variety of formats:
As a 4-digit string in the range '1901'
to '2155'
.
As a 4-digit number in the range 1901
to 2155
.
As a 1- or 2-digit string in the range '0'
to '99'
. Values in the ranges '0'
to '69'
and '70'
to '99'
are converted to YEAR
values in the ranges
2000
to 2069
and 1970
to 1999
.
As a 1- or 2-digit number in the range 1
to 99
. Values in the ranges 1
to 69
and 70
to 99
are
converted to YEAR
values in the ranges 2001
to
2069
and 1970
to 1999
.
Inserting a numeric 0
has a different effect for YEAR(2)
and YEAR(4)
. For YEAR(2)
, the result has a
display value of 00
and an internal value of 2000
. For YEAR(4)
, the result has a
display value of 0000
and an internal value of 0000
.
To specify zero for YEAR(4)
and have it be interpreted as 2000
, specify it as a string '0'
or
'00'
.
As the result of a function that returns a value that is acceptable in a YEAR
context, such as NOW()
.
Invalid YEAR
values are converted to 0000
.