Jump to content

Newer than 30 Days


doubledee

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/264680-newer-than-30-days/
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/264680-newer-than-30-days/#findComment-1356533
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.