找出哪个日期更大(意味着接近当前)

时间:2014-03-28 08:21:49

标签: php

我想找出哪个日期更大。但这里只有在情况总是如此的情况下......有什么问题可以解释它有什么问题..提前感谢...

$str1 = "Mar 27 2014";
$str2 = "Mar 29 2014";

if($str1<str2)
{
     echo 'str1 is smaller.';
}
else
{
     echo 'str1 is bigger';
}
$str = (strtotime($str2)) - (strtotime($str1));
echo floor($str/3600/24);

1 个答案:

答案 0 :(得分:0)

试试这个:

//Convert them into timestamps so that we can compare.
$date1 = strtotime("Mar 27 2014"); 
$date2 = strtotime("Mar 29 2014");

if($date1 > $date2){
    echo "$date1 is bigger than $date2!";
} 
elseif($date1 < $date2){
    echo "$date2 is bigger than $date1!";
}
else{
    echo "Both $date1 and $date2 are the same!";
}