in between dates

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

in between dates

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

What format is the date stored in news_date
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

Post by hame22 »

format is "YYYY-MM-DD", e.g. 2005-07-08

thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Look into DATE_SUB()
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

Code: Select all

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