Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较php中的日期字符串与mm-dd-yy格式_Php_Date_Datetime_Compare - Fatal编程技术网

比较php中的日期字符串与mm-dd-yy格式

比较php中的日期字符串与mm-dd-yy格式,php,date,datetime,compare,Php,Date,Datetime,Compare,我需要比较字符串中的两个日期, 我的约会: 第一天:11-11-19 第二天:11-24-17 所以我试着 $firstdate = "11-11-19"; $seconddate = "11-24-17"; if($firstdate < $seconddate) { echo "firstdate is minor than the secondate"; } else { echo "seconddate is maj

我需要比较字符串中的两个日期, 我的约会: 第一天:11-11-19 第二天:11-24-17

所以我试着

$firstdate = "11-11-19";
$seconddate = "11-24-17";

if($firstdate < $seconddate)
    {
        echo "firstdate is minor than the secondate";
    }
    else
    {
        echo "seconddate is major than the firstdate";
    }
$firstdate=“11-11-19”;
$seconddate=“11-24-17”;
如果($firstdate<$seconddate)
{
echo“firstdate比secondate小”;
}
其他的
{
echo“第二个日期比第一个日期重要”;
}
如果我改变<或>if语句应该改变,但我总是得到第一个日期。。。 如何比较本表格中的两个日期mm dd yy? 谢谢

您可以使用它将字符串转换为unix时间戳,并进行比较

$firstdate=strottime(“11-11-19”);
$seconddate=strottime(“11-24-17”);
如果($firstdate<$seconddate)
{
echo“firstdate比secondate小”;
}
其他的
{
echo“第二个日期比第一个日期重要”;
}

您可以将两个日期转换为时间戳:

echo (strtotime($firstdate) < strtotime($seconddate)) ? "firstdate is minor than the secondate" : "seconddate is major than the firstdate";
echo(strotime($firstdate)
我确信这不是故意的,但这与我之前发布的答案相同。:)