Getting mysql results based on date

Associate
Joined
19 Jun 2006
Posts
162
Location
Swansea, Wales
Hi,

I am trying to add a menu to the front page of my site that displays recently added items. Each item is in a mysql table with a dateadded field in the format (Y-m-d).

I want to run a query that will extract say, the last month of entries. Anyone got any ideas on the query?

I tried

Code:
SELECT * FROM `mbs_trumps` WHERE `dateadded` > "$thisYear-$thisMonth-%" ORDER BY `dateadded` DESC

where this month and this year is just using the appropriate date() function.

It wont work because i'm betting that date in the mysql database can not be compared as a number. So, any other ideas?

Thanks
 
Found the solution...

'SELECT * FROM `mbs_trumps` WHERE `dateadded` > DATE_SUB( CURDATE( ) , INTERVAL 31 DAY ) ORDER BY `dateadded` DESC'
 
Back
Top Bottom