mysql时间类型year

`date:年月日

datetime:年月日时分秒,保存确定的时间点的时候,存储形式yyyy-mm-dd hh:MM-dd,暂用8个字节

timestamp:时间从.存储时是整形数字,表现形式是yyyy-mm-dd hh:MM-dd,暂用4个字节,取值范围,1970-01-01 00:00:00到2038

year:1个字节   1901-2155,可以用0000表示默认值,如果输入两位'00-69'表示'2000-2069',如果输入'70-99'表示'1970-1999'

----------------------------------------
针对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)

mysql> select * from history;
+-------+-------+
| title | years |
+-------+-------+
| 00    |  2000 |
| 69    |  2069 |
| 70    |  1970 |
| 99    |  1999 |
+-------+-------+
4 rows in set (0.00 sec)

为了便于理解,输入的时候输入4位范围内的数字
mysql> insert into history values ('minyear','1901'),('maxyear','2155');
Query OK, 2 rows affected (0.03 sec)
Records: 2  Duplicates: 0  Warnings: 0

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)

--------------------------------------`

转载于:https://my.oschina.net/u/2253438/blog/678875

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值