Reputation: 5166
how can i query my mysql database and fetch rows which are posted in earlier 3 days
i know how to fetch todays's rows but not 3 days ago
time will save in my table like this :
2010-01-20 19:17:49
and this is what i know :
SELECT id FROM pages WHERE date=now()
but i need to show posts in 3days
and im looking for a simple and straight solution ,because i know how to do so in long php codes
Upvotes: 2
Views: 221
Reputation: 11824
This should select all entries with a date value after and including 3 days ago:
Select id From pages Where NOW() >= Interval date day + 3
Note that if there are dates in the future this will select them too.
Upvotes: 1
Reputation: 332791
To get records three days in the past up to current time:
SELECT t.id
FROM PAGES t
WHERE t.date BETWEEN DATE_SUB(NOW(), INTERVAL 3 DAY) AND NOW()
Upvotes: 3
Reputation: 3573
Would be helpful to know what version of MySQL you're using and what column type we're talking about but here's the reference of Date and Time Functions for 5.1. You're going to probably want DATE_SUB().
Upvotes: 0