List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:May 2 2002 1:28am
Subject:Re: Select Past 7 days
View as plain text  
At 20:52 -0400 5/1/02, Anthony W. Marino wrote:
>Try this:
>
>SELECT a, b FROM tblName WHERE TO_DAYS(NOW()) - TO_DAYS(pubDate) <= 7;
>
>Anthony

SELECT a, b FROM tblName WHERE pubDate >= DATE_SUB(NOW(),INTERVAL 7 DAY);

will probably be faster if pubDate is indexed.  The first query
above puts pubDate in an expression, which makes indexes inapplicable.

>
>
>>  What is the proper query for slect all from the past
>>  number of days.
>>
>>  i.e. I would like to return all articles from the past
>>  week. Right now I am using SELECT blah, bla FROM table
>>  WHERE pubDate BETWEEN CURDATE() - 7 AND CURDATE() AND
>>  whatever = 'whatever'
>>
>>  This worked fine until today. the first of month.
>>
>>  Thanks much,
>  > olinux

Thread
Select Past 7 daysolinux2 May
  • Re: Select Past 7 daysAnthony W. Marino2 May
    • Re: Select Past 7 daysPaul DuBois2 May