Mac Taylor
Mac Taylor

Reputation: 5166

query mysql table and fetch rows posted in 3 days

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

Answers (3)

Trey Hunner
Trey Hunner

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

OMG Ponies
OMG Ponies

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

Jeff Swensen
Jeff Swensen

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

Related Questions