faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

23 of 27 people (85%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I select all rows that have a date column more than one week old?

Sep 17th, 1999 01:40
Nathan Wallace, Chris Cosentino


Well, if you are using MySQL and you have a field with a DATE type that 
you want to run a query against, you can do something like this:

    $query = mysql_query("select * from news where
                          (to_days(now())-to_days(news.date))>='7'");
    while ($myrow = mysql_fetch_array($query)) {
        #Do stuff to $myrow...
    }