如何从2小时前选择值

时间:2017-04-19 08:42:33

标签: mysql

我对mysql查询知之甚少..而且我试图从现在开始的两个小时后从数据库中获取值..我已经搜索了它,我也发现了一些相关的帖子..但是不幸的是我无法实现逻辑..请帮我解决这个问题..

这是mysql查询

select * 
from `ordermaster` 
where ((
`ordermaster`.`Pick_date`
 = curdate())
 and (`ordermaster`.`Pick_time`
 <= (now() - interval 2 hour)) 
and (`ordermaster`.`Status` 
= 2))

是,Pick_Date =&#34; 2017-04-19&#34; (今天约会)和Pick_Time =&#34; 10:00:00&#34; (24小时格式)

2 个答案:

答案 0 :(得分:0)

您可以使用between关键字

select  *
from    `ordermaster` 
where   `Pick_date` = curdate() and
        `Pick_time` between (now() - interval 2 hour) and now() and
        `Status` = 2

修改

根据我们的聊天情况,我们发现GoDaddy服务器,您托管的数据库比当地时间提前12.5小时,您应该使用的最终查询是

select  *
from    `ordermaster` 
where   `Pick_date` = curdate() and
        `Pick_time` <= now() + interval 10 hour + interval 30 minute and
        `Status` = 2

答案 1 :(得分:0)

尝试以下内容:

Select * From ordermaster om
Where  Concat(om.Pick_date,' ', om.Pick_time) as date Between 
       (now() - interval 2 hour) and now()
       AND Status = 2