[英]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.