1、创建数据库
create table t1 (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
d1_data date,
d2_time time,
d3_datatime datetime,
d4_year year,
d5_timestamp TIMESTAMP
);
字符串方式插入
INSERT INTO t1 (d1_data,d2_time,d3_datatime,d4_year,d5_timestamp) VALUES(NOW(),NOW(),NOW(),NOW(),NOW());
mysql> select * from t1 where id=1\G
*************************** 1. row ***************************
id: 1
d1_data: 2018-06-15
d2_time: 13:50:25
d3_datatime: 2018-06-15 13:50:25
d4_year: 2018
d5_timestamp: 2018-06-15 13:50:25
1 row in set (0.00 sec)
INSERT INTO t1 (d1_data,d2_time,d3_datatime,d4_year,d5_timestamp) VALUES(‘2018-06-15‘,‘13:50:25‘,‘2018-06-15 13:50:25‘,‘2018‘,‘2018-06-15 13:50:25‘);
mysql> select * from t1 where id=2\G
*************************** 1. row ***************************
id: 2
d1_data: 2018-06-15
d2_time: 13:50:25
d3_datatime: 2018-06-15 13:50:25
d4_year: 2018
d5_timestamp: 2018-06-15 13:50:25
1 row in set (0.00 sec)
1.1、date (数字插入)
mysql> help DATE
A date. The supported range is ‘1000-01-01‘ to ‘9999-12-31‘. MySQL
displays DATE values in ‘