Reputation: 10117
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
Upvotes: 2
Views: 3643
Reputation: 27573
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);
Upvotes: 2
Reputation: 332741
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
Upvotes: 2
Reputation: 99841
Provided timestamps and the MySQL are in the same timezone, you can just compare to NOW()
.
SELECT * FROM tbl WHERE date_col < NOW()
Upvotes: 7