tags:

views:

65

answers:

3

I have a mysql table with fields for a start and end date/time.

How would i select just the rows that are older than the current date using php.

The format of the end-date is 2009-11-25 08:01:00 and the field type is datetime

+3  A: 

Provided timestamps and the MySQL are in the same timezone, you can just compare to NOW().

SELECT * FROM tbl WHERE date_col < NOW()
Dominic Rodger
That works provided your time zone never changes; for example daylight saving time.But if you're sane you'll set all your servers clocks to UTC.
MarkR
@MarkR: look up NTP
OMG Ponies
+2  A: 

It might look something like:

$result = mysql_query('SELECT * FROM mytable WHERE datefield < NOW()');
if (! $result) { die(mysql_error()); }
while ($row = mysql_fetch_assoc($result)) {
    // handle contents of $row
}
mysql_free_result($result);
jheddings
+1  A: 

Your SQL query would resemble:

SELECT *
  FROM your_table t
 WHERE t.end-date < CURDATE()

There's various synonyms supported to get the current date - NOW(), SYSDATE()...

Reference: MySQL date related functions

OMG Ponies
A hyphen in the middle of a column name is surely a recipe for disaster.
Dominic Rodger
I agree - I forgot to comment on it in my haste, but it is the column name supplied by the OP.
OMG Ponies
Ah - missed that.
Dominic Rodger