From http://www.highlystructured.com/comparing_dates_php.html
$todays_date = date("Y-m-d");
Now was the tricky part, comparing the two dates. Having been stuck with two dates in the YYYY-MM-DD format, I really had to do some experimenting. Without going into too much detail, I was left to compare each segment of the date. I had to use the PHP explode function to break apart each segment into an array, and compare values using a long string of if-then statements. If today's year was less than the coupon's expiration date year, it was expired. If it the years were the same, then I had to compare the months. If the months were the same, I had to compare days.
Uh-huh.
$past_y = '1999-12-31';
$past_m = '2007-03-28';
$past_d = '2007-05-10';
$today = '2007-05-25';
$futr_d = '2007-05-31';
$futr_m = '2007-07-12';
$futr_y = '2012-01-01';
function compare($a)
{
$today = '2007-05-25';
if($a==$today)
{
echo "That's today!\n";
return;
}
echo "$a is ",($a<$today ? 'before' : 'after')," $today\n";
}
compare($past_y);
compare($past_m);
compare($past_d);
compare($today);
compare($futr_d);
compare($futr_m);
compare($futr_y);
1999-12-05 is before 2007-05-25
2007-03-28 is before 2007-05-25
2007-05-10 is before 2007-05-25
That's today!
2007-05-31 is after 2007-05-25
2007-07-12 is after 2007-05-25
2012-01-01 is after 2007-05-25
That's one reason why the ISO standard specifies fullyear-month-day with zero-padding: so that string comparison works.