日期类型
create table tim(
tim time,
dat date,
tims timestamp,
dateti datetime
);
insert into tim(tim,dat,tims,dateti) values(now(),now(),now(),now());
select * from tim;
+----------+------------+---------------------+---------------------+
| tim | dat | tims | dateti |
+----------+------------+---------------------+---------------------+
| 00:58:02 | 2017-09-25 | 2017-09-25 00:58:02 | 2017-09-25 00:58:02 |
| 00:24:46 | 2017-09-25 | 2017-09-25 00:24:46 | 2017-09-25 00:24:46 |
+----------+------------+---------------------+---------------------+
datetime(年月日时分秒)与timestamp类型(时间戳)
create table t_7(
a datetime,
b timestamp
);
例: insert into t_7 values('2012-08-08 08:08:08', 54389867575365); --报错, 时间戳存储时是整形,但是表示是日期型
例: insert into t_7 values('2012-08-08 08:08:08', '2012-08-08 08:08:08');
例: select a+0, b+0 from t_7; --在检索时如果列+0, 时间的格式会整形来显示
+-----------------------+----------------+
| a+0 | b+0 |
+-----------------------+----------------+
| 20120808080808.000000 | 20120808080808 |
+-----------------------+----------------+
例: insert into t_7 values('2012-08-08 08:08:08', '2038-01-20'); --报错
例: insert into t_7 values('2012-08-08 08:08:08', '2038-01-19'); --不报错
例: insert into t_7 values('2012*08*08', '2038*01*19'); --支持任意的分隔符日期
例: insert into t_7 values('20120808', '20380119'); --也可以不用写分隔符
例:insert into t_7 values('20128808', '20380119'); --报错
create table t(
name varchar(10) not null default"n",
sex varchar(1) not null default "m",
sjc timestamp not null default current_timestamp
sjcc timestamp not null default current_timestamp ON UPDATE CURRENT_TIMESTAMP
);
datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
create table tim(
tim time,
dat date,
tims timestamp,
dateti datetime
);
insert into tim(tim,dat,tims,dateti) values(now(),now(),now(),now());
create table n1(
t timestamp not null default now(),
dt datetime not null default now()
);
insert into n1(t,dt) values("2017/09/26 19:42:00")
insert into n1(t,dt) values("2017/09/26 19:42:00","19:42:00")
网友评论