[英]Comparing dates in MySQL Database
在PHP方面经验丰富,我缺乏比较数据库中两个日期的领域。
我在数据库中存储了两个值。 这仅仅是Unix时间戳。
值1: post_time
值2: expire_time
过期时间仅是发布时间之后的7天。 我只需要获取所有尚未“过期”的帖子。
目前我一直在使用: if(($post['post_time']) >= time() - (60*60*24*7))
,它可以正常工作。 但我宁愿在查询中找到解决方案以获取结果。 而不是提取所有结果,然后稍后对其进行过滤。
这是我的查询:
SELECT id, uid, title, description,
price, image, tags, post_type,
category, post_time, expire_time
FROM posts
ORDER BY RAND() LIMIT 8
感谢您的帮助。
就像@Dagon那样做:
SELECT id, uid, title, description,
price, image, tags, post_type,
category, post_time, expire_time
FROM posts WHERE post_time >= UNIX_TIMESTAMP(NOW()) - (60*60*24*7)
ORDER BY RAND() LIMIT 8
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.