我将日期格式化为美国风格格式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声明中。我在这里错过了什么?
用strtotime()
这样做,
$startDate = strtotime($startDate);
$stopDate= strtotime($stopDate);
$nextDate =strtotime("today");
if ($nextDate >= $startDate && $nextDate <= $stopDate) {
...
do stuff
...
}