View Single Post

  #1 (permalink)  
Old 11-28-2005
Peter
 
Posts: n/a
Default selecting by date

Suppose I have a month and a year (this is for a blog application):

$month = 10; // October
$year = 2005; // year 2005

I'd like to select items on or before the last day of October 2005 in
descending order. My first attempt was:

echo "SELECT * FROM $tblPosts " .
"WHERE MONTH(postDate)<=$month & YEAR(postDate)<=$year " .
"ORDER BY postDate DESC, id DESC LIMIT $to_request");

but for some reason, this is selecting ALL records.


Given a month and year, how do I select any item with a postDate (which is a
datetime field) on the last day of the month or earlier in the same year?

Thanks!
Pete
Reply With Quote