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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.