本文介绍了立即完成帖子,但至少要早20分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
除了最近20分钟内发布的帖子外,我都希望获得今天发布的所有帖子.
I want to get the posts from today that I made, all of them, except the ones that I posted in the last 20 minutes.
例如,现在是3:30.
for example, now is 3:30.
我希望获得直到3:10为止的所有帖子.
I want to get all posts that I did today until 3:10.
我尝试过:
SELECT id, titulo
FROM posts
WHERE data > DATE_SUB(NOW(), INTERVAL 20 MINUTE)
ORDER BY RAND()
但没有成功.怎么了?
推荐答案
您的查询设置为获取过去20分钟内的帖子,如果今天要获取过去20分钟之外的内容,则应使用data < DATE_SUB( NOW( ) , INTERVAL 20MINUTE )
,且不得大于
Your query is set to get posts from the last 20 minutes, if you want today except the last 20 minutes, you should use data < DATE_SUB( NOW( ) , INTERVAL 20MINUTE )
and not bigger than.
第二部分(从今天开始)可以使用 curdate()函数:
The second part (from today) can be done with curdate() function:
CURDATE() = DATE(data)
一起:
SELECT id, titulo
FROM posts WHERE
data < DATE_SUB( NOW( ) , INTERVAL 20 MINUTE )
AND
CURDATE() = DATE(data)
ORDER BY RAND( )
这篇关于立即完成帖子,但至少要早20分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!