doubledee Posted June 24, 2012 Share Posted June 24, 2012 I only want to display Comments that have been made within the last 30 days. In my Comments table, I have a "created_on" field which is populated with NOW() like this... // Build query. $q3 = "INSERT INTO comment(article_id, member_id, comment_no, body, created_on) VALUES(?, ?, ?, ?, NOW())"; What do I need to do, so when I create my SELECT query to display the Comments, it only shows Comments "created on" from the current moment to back to 30 days old? Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/264680-newer-than-30-days/ Share on other sites More sharing options...
requinix Posted June 24, 2012 Share Posted June 24, 2012 DATE_SUB is a good place to start. Quote Link to comment https://forums.phpfreaks.com/topic/264680-newer-than-30-days/#findComment-1356532 Share on other sites More sharing options...
doubledee Posted June 24, 2012 Author Share Posted June 24, 2012 DATE_SUB is a good place to start. How does this look... SELECT c.member_id, a.slug, a.heading, LEFT(c.body, 30) AS body, c.created_on, c.id FROM article AS a INNER JOIN comment AS c ON a.id=c.article_id WHERE member_id=35 AND comment_approved=1 AND c.created_on >= DATE_SUB(now(), INTERVAL 30 DAY) ORDER BY created_on DESC Debbie Quote Link to comment https://forums.phpfreaks.com/topic/264680-newer-than-30-days/#findComment-1356533 Share on other sites More sharing options...
Barand Posted June 24, 2012 Share Posted June 24, 2012 An alternative is AND c.created_on >= NOW() - INTERVAL 30 DAY Quote Link to comment https://forums.phpfreaks.com/topic/264680-newer-than-30-days/#findComment-1356647 Share on other sites More sharing options...
doubledee Posted June 24, 2012 Author Share Posted June 24, 2012 An alternative is AND c.created_on >= NOW() - INTERVAL 30 DAY Okay, thanks. Debbie Quote Link to comment https://forums.phpfreaks.com/topic/264680-newer-than-30-days/#findComment-1356648 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.