mysql 日期型比较操作

mysql> create table t10(id int,start_dt date);
Query OK, 0 rows affected (0.89 sec)

mysql> desc t10
    -> ;
+----------+---------+------+-----+---------+-------+
| Field    | Type    | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| id       | int(11) | YES  |     | NULL    |       |
| start_dt | date    | YES  |     | NULL    |       |
+----------+---------+------+-----+---------+-------+
2 rows in set (0.04 sec)

mysql> insert into t10 values(1,2010-01-01);
ERROR 1292 (22007): Incorrect date value: '2008' for column 'start_dt' at row 1
mysql> insert into t10 values(1,20100101);
Query OK, 1 row affected (0.05 sec)

mysql> insert into t10 values(2,20100201);
Query OK, 1 row affected (0.00 sec)


insert into t10 values(3,20100301);
insert into t10 values(3,20100301);
insert into t10 values(4,20100401);
insert into t10 values(5,20100501);
insert into t10 values(6,20100601);
insert into t10 values(7,20100701);
insert into t10 values(8,20100801);
insert into t10 values(9,20100901);


mysql>  select * from t10 where start_dt >20100201 and start_dt<20100601;
+------+------------+
| id   | start_dt   |
+------+------------+
|    3 | 2010-03-01 |
|    3 | 2010-03-01 |
|    4 | 2010-04-01 |
|    5 | 2010-05-01 |
+------+------------+
4 rows in set (0.00 sec)

原文地址:https://www.cnblogs.com/hzcya1995/p/13351738.html