I am trying to compare today and a given date in PHP, and I am getting some unexpected results.
Here is some output I have:
echo time(); // 1315940430
echo strtotime("+20 days", $date_string); // 1730010
echo $date_string; // 2010-9-30
and when I try something like this:
if (date() > date('Y-m-d', strtotime("+20 days", $date_string)))
{
}
And the check always returns true no matter what the $date_string is. Any idea how to fix this?
Update:
The reason is because the 2nd part of your if statement is in
1970!That’s why it always returns true.
See demo: http://codepad.org/tmmuoSXv
Code:
Output:
SOLVED:
What you to do is this:
The extra
strtotimefixes it all up for you and you get the correct date 🙂Demo: http://codepad.org/Fhnx5er0
Demo(if is false): http://codepad.org/jsnEMUGI