Page 1 of 1

in between dates

Posted: Mon Jul 10, 2006 7:37 am
by hame22
Hi

I am looking to return a list of news articles published from the last 10 days.

What I want to do is run a query that pickas out all news articles within between today and 10 days before.

I am using a query in my script to do this which looks like this :

Code: Select all

$result = mysql_query("Select * from news where news_date between now() - 10 AND now()");
I know this is wrong, could anyone give me some tips?

Thanks in advance

Posted: Mon Jul 10, 2006 8:02 am
by JayBird
What format is the date stored in news_date

Posted: Mon Jul 10, 2006 8:28 am
by hame22
format is "YYYY-MM-DD", e.g. 2005-07-08

thanks

Posted: Mon Jul 10, 2006 8:33 am
by feyd
Look into DATE_SUB()

Posted: Mon Jul 10, 2006 8:56 am
by jamiel

Code: Select all

SELECT * FROM news WHERE news_date BETWEEN NOW() AND DATE_SUB(NOW(), INTERVAL 10 DAY)