MySQL 查询大于“时间字段”15分钟、1小时、1天的数据
以下代码中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);
相应的如果想查询前一天的数据,加一个“-”号即可
博客园:https://www.cnblogs.com/huixincode
如果此文章对您有所帮助记得打赏哦,一分也是对我的支持和鼓励,谢谢!
转载文章请务必保留出处和署名,谢谢!
如果此文章对您有所帮助记得打赏哦,一分也是对我的支持和鼓励,谢谢!
转载文章请务必保留出处和署名,谢谢!