I would like to show only dates from a MySQL database that have not expired. Don't know if I can do this in the select statement or how to do it with an IF statement in the PHP. I just need to compare the date in the database with today's date and if it is >= today's date then show the information for this record. Sounds simple, but I'm an idiot! Please help.
Show only current and future dates from a MySQL database
$Sql="SELECT DATEFIELD FROM DB WHERE DATEFIELD >='".date("Y-m-Y")."'";
(don't remember if it is >= or =>.)
I suppose it depends on how you are storing your datefield.
Assuming your datefield is timestamp(14) you might use...
$sql = "SELECT * FROM [table] WHERE [timefield] >= now() +0";
That will give you up to the second results.
if you don't have the time in your timestamp you could use
$sql = "SELECT * FROM [table] WHERE [timefield] >= CURDATE() +0";
That way you can have up to the second results.
BTW...it's usually quicker if you let mysql do the work
oh yeah and this always helps