Vy Le
Vy Le

Reputation: 69

How to compare date() in mysql query?

In mysql date is formated as yyyy-mm-dd. I would to retrieve all related posts that is more then 25 days old.

Something like this:

SELECT * FROM post WHERE writtenday >= 25;

Many thanks

Upvotes: 0

Views: 67

Answers (2)

Wizard
Wizard

Reputation: 11265

SELECT * FROM post WHERE DATEDIFF(CURDATE(), writtenday) >= 25;

Upvotes: 1

Andy
Andy

Reputation: 50560

You can use the DATE_SUB function

WHERE writtenday <= DATE_SUB(NOW(), INTERVAL 25 DAY)

This will retrieve anything that is older than TODAY-25 Days

Upvotes: 0

Related Questions