我需要比较字符串中的两个日期, 我的日期: 第一次约会: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";
}
如果我改变&lt;或者&gt; if语句应该改变,但我总是得到第一个... 怎么做比较这个形式mm-dd-yy中的两个日期? 感谢
答案 0 :(得分:-1)
您可以使用strtotime将字符串转换为unix时间戳,并将其进行比较。
$firstdate = strtotime("11-11-19");
$seconddate = strtotime("11-24-17");
if($firstdate < $seconddate)
{
echo "firstdate is minor than the secondate";
}
else
{
echo "seconddate is major than the firstdate";
}
答案 1 :(得分:-1)
您可以将这两个日期转换为时间戳:
echo (strtotime($firstdate) < strtotime($seconddate)) ? "firstdate is minor than the secondate" : "seconddate is major than the firstdate";