Query mysql table and get rows published in 3 days

how can i query my mysql database and get rows that are sent in earlier 3 days

I know how to fetch the current lines, but not 3 days ago

the time will be stored 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 messages in 3 days

and im looking for a simple and straight forward solution because i know how to do it in long php codes

+2


a source to share


3 answers


To get records three days prior to the last time:



SELECT t.id
  FROM PAGES t
 WHERE t.date BETWEEN DATE_SUB(NOW(), INTERVAL 3 DAY) AND NOW()

      

+3


a source


This should select all records with a date after 3 days ago:

Select id From pages Where NOW() >= Interval date day + 3

      



Note, if there are dates in the future, this will pick them as well.

+1


a source


It would be helpful to know which version of MySQL you are using and what type of column we are talking about, but here's a link to date and time functions for 5.1. You probably need DATE_SUB () .

0


a source







All Articles