日期和时间类型
一、日期和时间类型
类型 | 字节 | 最小值 | 最大值 |
---|---|---|---|
date | 4 | 1000-01-01 | 9999-12-31 |
datetime | 8 | 1000-01-01 00:00:00 | 9999-12-31 23:59:59 |
timestamp | 4 | 1970-01-01 00:00:01 | 2038-01-19 03:14:07 |
time | 3 | -838:59:59 | 838:59:59 |
year | 1 | 1000 | 9999 |
--查看当前时间“年、月、日、时、分、秒”
select now();
--查看当前日期
select curdate();
--查看当前年
select year(now());
列
创建表
create table test_date
(
value1 date,
value2 datetime,
value3 timestamp,
value4 time,
value5 year
);
插入数据
insert into test_date
(value1,value2,value3,value4,value5)
value
(curdate(),now(),now(),time(now()),year(now()));
insert into test_date
(value1,value2,value3,value4,value5)
value
("2021-10-22","2021-10-12 12:23:59","2021-10-22 23:23:59","23:12:13","2022");