PHP日期比较给出了意想不到的结果

问题描述 投票:-1回答:1

我将日期格式化为美国风格格式mm/dd/yyyy(没有时间)并比较日期但未获得预期结果。

echo $startDate ;  // 09/14/2018
echo $nextDate ;   // 03/08/2019
echo $stopDate ;   // 03/08/2019

以下方式创建上述变量:

$nextDate = date('m/d/Y',strtotime("today")) ;

然后将日期比较为:

if ($nextDate >= $startDate && $nextDate <= $stopDate) {
  ...
  do stuff
  ...
}

$nextDate大于$startdate并且等于$stopDate但它没有在IF声明中。我在这里错过了什么?

php strtotime date-arithmetic date-comparison
1个回答
1
投票

strtotime()这样做,

$startDate = strtotime($startDate);
$stopDate= strtotime($stopDate);
$nextDate =strtotime("today");

if ($nextDate >= $startDate && $nextDate <= $stopDate) {
  ...
  do stuff
  ...
}

工作演示:https://3v4l.org/BWZN5

© www.soinside.com 2019 - 2024. All rights reserved.