MySQL WHERE 日期时间早于某个时间(例如 15 分钟)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18726873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WHERE datetime older than some time (eg. 15 minutes)
提问by Hydra IO
I was looking at:
我在看:
MySQL Select rows where timestamp column between now and 10 minutes ago
I have a col named creation_date
holding a datetime stamp: 2013-09-10 11:06:42
我有一个名为 colcreation_date
持有日期时间戳:2013-09-10 11:06:42
I would like to pull all records that are OLDER than 15 minutes using:
我想使用以下方法提取所有超过 15 分钟的记录:
WHERE creation_date >= DATE_SUB(NOW(),INTERVAL 15 MINUTE)
WHERE creation_date >= DATE_SUB(NOW(),INTERVAL 15 MINUTE)
However the query always returns 0 results, even with items older then 15 minutes present in the database.
但是,查询始终返回 0 结果,即使数据库中存在 15 分钟之前的项目也是如此。
回答by dognose
older would be WHERE creation_date < DATE_SUB(NOW(),INTERVAL 15 MINUTE)
年纪大了 WHERE creation_date < DATE_SUB(NOW(),INTERVAL 15 MINUTE)
回答by simhumileco
There are many ways to achieve this with INTERVAL
. I will present three:
有很多方法可以使用INTERVAL
. 我将介绍三个:
first:
第一的:
WHERE creation_date < DATE_SUB( NOW(), INTERVAL 15 MINUTE )
second:
第二:
WHERE creation_date < NOW() - INTERVAL 15 MINUTE
third:
第三:
WHERE creation_date < NOW() + INTERVAL -15 MINUTE