mysql between and 遇到日期查询边界问题
2017-06-28 14:11
471 查看
最近实现一个按日期范围查询列表,例如输入的是日期 2015-11-01到2015-11-03,想得到1号到3号的数据,
执行 select * from table where create_date between '2015-11-01' and '2015-11-03' 结果是1号到2号的数据,这是因为时间范围是1号0时0分0秒到3号0时0分0秒之间的数据,
只需要把后面的日期加一天即可。
修改,使用date_add方法
select * from table where create_date between '2015-11-01' and date_add('2015-11-03',interval 1 day);
OK!
MySQL 日期加减:
DATE_ADD(date,INTERVAL expr type) --加法
DATE_SUB(date,INTERVAL expr type) --减法
执行 select * from table where create_date between '2015-11-01' and '2015-11-03' 结果是1号到2号的数据,这是因为时间范围是1号0时0分0秒到3号0时0分0秒之间的数据,
只需要把后面的日期加一天即可。
修改,使用date_add方法
select * from table where create_date between '2015-11-01' and date_add('2015-11-03',interval 1 day);
OK!
MySQL 日期加减:
DATE_ADD(date,INTERVAL expr type) --加法
DATE_SUB(date,INTERVAL expr type) --减法
相关文章推荐
- mysql between and 遇到日期查询边界问题
- mysql between and 遇到日期查询边界问题
- mysql between and 遇到日期查询边界问题
- oracle日期时间段查询遇到问题to_date ora-01847 day of month must be between 1 and last day of month
- mysql between and 边界值及php月初月末的问题
- mysql between 开始日期 AND 结束日期的问题
- MySQL中日期比较时遇到的编码问题解决办法
- mysql 设计遍历查询结果中的每行数据遇到的诸多问题
- MySQL中日期比较时遇到的编码问题解决办法
- MySQL 查询中遇到的若干问题
- MySQL 查询中遇到的若干问题
- MySQL 查询中遇到的若干问题
- MySQL 查询中遇到的若干问题
- mysql的between的边界问题
- mysql查询安装目录与安装mysql时候如果遇到什么public key not installed 问题解决方案。
- MySQL 查询中遇到的若干问题
- day17 oracle ----查询(select) ---(BETWEEN ... AND... ,IN(list), LIKE , IS NULL , AND ,OR, NOT) ---(字符 , 数字 ,日期, 转换
- 关于SQL中Between语句查询日期的问题
- mysql的between的边界问题
- MySQL 查询中遇到的若干问题