date_add和interval在MySQL中如何工作?
我尝试从表中选择数据时间距现在不超过 1 分钟的行。我尝试按以下方式执行此操作:
SELECT datetime FROM my_table
WHERE datetime > date_add( curdate( ) , INTERVAL -1 MINUTE )
这就是我得到的:
2011-09-23 02:39:53
2011-09-23 08:10:07
这显然是错误的。有人知道为什么吗?
添加
看起来真的很奇怪。如果我使用间隔 -1 小时,我会得到 4 或 7 小时前的结果(我不应该得到它们),但我会过滤超过 14 小时的结果。怎么可能呢?
I try to select those rows from the table in which datatime is withing 1 minute from now. I try to do it in the following way:
SELECT datetime FROM my_table
WHERE datetime > date_add( curdate( ) , INTERVAL -1 MINUTE )
This is what I get:
2011-09-23 02:39:53
2011-09-23 08:10:07
Something is clearly wrong with that. Does anybody know why?
ADDED
It looks really strange. If I use interval -1 hour
I got results which are 4 or 7 hours old (I should not get them) but I do filter results which are older than 14 hours. How is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从过去一分钟到未来一分钟:
从现在到未来一分钟:
从过去一分钟到现在:
From one minute in the past to one minute in the future:
From now to one minute in the future:
From one minute in the past to now: