首页 > 数据库技术 > 详细

MySQL 查询大于“时间字段”15分钟、1小时、1天的数据

时间:2019-11-22 12:06:31      阅读:277      评论:0      收藏:0      [点我收藏+]

以下代码中times为时间字段,类型为datetime

1.查询大于times十五分钟的数据

//大于号后面都是获取times十五分钟后的时间
select*from table where now() >SUBDATE(times,interval -15 minute);
select*from table where now() > SUBDATE(times,interval -900 second);
select*from table where now() > date_add(times,interval 15 minute);
select*from table where now() >ADDDATE(times,interval 15 minute);

2.查询大于times一小时的数据

//大于号后面都是获取times一小时后的时间
select*from table where now() >SUBDATE(times,interval -1 hour);
select*from table where now() > SUBDATE(times,interval -60*60 second);
select*from table where now() > date_add(times,interval -1 hour);
select*from table where now() >ADDDATE(times,interval 15 hour);

3.查询大于times一天的数据

//大于号后面都是获取times一天后的时间
select*from table where now() >SUBDATE(times,interval -1 day);
select*from table where now() > SUBDATE(times,interval -60*60*60 second);
select*from table where now() > date_add(times,interval -1 day);
select*from table where now() >ADDDATE(times,interval 15 day);

相应的如果想查询前一天的数据,加一个“-”号即可

MySQL 查询大于“时间字段”15分钟、1小时、1天的数据

原文:https://www.cnblogs.com/liangzia/p/11910379.html

(0)
(0)
   
举报
评论 一句话评论(0
分享档案
最新文章
教程昨日排行
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!