The YEAR
Type
The YEAR
type is a one-byte type used for representing years. It can be declared as YEAR(2)
or YEAR(4)
to specify a display width of two or four characters. The default is four characters if no width is given.
For four-digit format, MariaDB displays YEAR
values in YYYY
format, with a range of 1901
to 2155
, or 0000
. For two-digit format, MariaDB 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 four-digit string in the range
'1901'
to'2155'
. - As a four-digit number in the range
1901
to2155
. - As a two-digit string in the range
'00'
to'99'
. Values in the ranges'00'
to'69'
and'70'
to'99'
are converted toYEAR
values in the ranges2000
to2069
and1970
to1999
. - As a two-digit number in the range
1
to99
. Values in the ranges1
to69
and70
to99
are converted toYEAR
values in the ranges2001
to2069
and1970
to1999
. Note that the range for two-digit numbers is slightly different from the range for two-digit strings, because you cannot specify zero directly as a number and have it be interpreted as2000
. You must specify it as a string'0'
or'00'
or it is interpreted as0000
. - As the result of a function that returns a value that is acceptable in a
YEAR
context, such asNOW()
.
Illegal YEAR
values are converted to 0000
.
See also , "Two-Digit Years in Dates".