Possible Duplicate:
PHP: Date larger than current date
I have my dates in this format: dd-mm-yyyy
Now according to php, 28-06-2011 is bigger than 01-11-2011
$today = date('d-m-Y', time());
if("28-06-2011" > $today ){
echo "This returns true";
}
How can i make this work properly?
You can’t compare dates like that. They’re two strings. PHP will try to interpret them as numbers (taking the first two digits and then failing because of theTurns out this is not correct.-) and compare those.YYYY-MM-DDtype strings can indeed be compared using>and<.So refer to Col. Shrapnel’s answer and change your date format – it makes sense anyway. If you can’t do that (because it’s a user-input date or whatever), you can create two
DateTimeobjects which, thanks to PHP 5 magic, you can also compare like this: