Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Year Type

Tags:

date

mysql

Why does the MySQL year type limit the range of allowable years between 1901 and 2155?

like image 838
just_wes Avatar asked Mar 22 '10 19:03

just_wes


2 Answers

Presumably, if you are storing more recent dates, you will never need more than 256 possible year values, which fits exactly into one byte. This saves you significant amounts of space: rather than using multiple bytes to store the integer 1901, 1900 years of which can be considered redundant in many cases, MySQL internally treats it as just the number 1, and displays it at 1901 for your benefit.

If you need more years, use an INT-based type.

like image 68
Matchu Avatar answered Oct 07 '22 00:10

Matchu


In order to fit the value into a single byte. The choice of 1901-2155 is arbitrary, but the fact that it supports 1-byte worth of values is not.

like image 43
Ike Walker Avatar answered Oct 07 '22 02:10

Ike Walker