`date:年月日mysql
datetime:年月日時分秒,保存肯定的時間點的時候,存儲形式yyyy-mm-dd hh:MM-dd,暫用8個字節sql
timestamp:時間從.存儲時是整形數字,表現形式是yyyy-mm-dd hh:MM-dd,暫用4個字節,取值範圍,1970-01-01 00:00:00到2038it
year:1個字節 1901-2155,能夠用0000表示默認值,若是輸入兩位'00-69'表示'2000-2069',若是輸入'70-99'表示'1970-1999'table
----------------------------------------
針對year類型
create table history(
title VARCHAR(20) not null DEFAULT '',
years YEAR(4)
)
輸入:00或69或70或99
mysql> insert into history VALUES ('00','00'),('69','69'),('70','70'),('99','99');
Query OK, 4 rows affected (0.08 sec)date
mysql> select * from history;
+-------+-------+
| title | years |
+-------+-------+
| 00 | 2000 |
| 69 | 2069 |
| 70 | 1970 |
| 99 | 1999 |
+-------+-------+
4 rows in set (0.00 sec)select
爲了便於理解,輸入的時候輸入4位範圍內的數字
mysql> insert into history values ('minyear','1901'),('maxyear','2155');
Query OK, 2 rows affected (0.03 sec)
Records: 2 Duplicates: 0 Warnings: 0im
mysql> select * from history;
+---------+-------+
| title | years |
+---------+-------+
| 00 | 2000 |
| 69 | 2069 |
| 70 | 1970 |
| 99 | 1999 |
| minyear | 1901 |
| maxyear | 2155 |
+---------+-------+
6 rows in set (0.00 sec)datetime
--------------------------------------`tab