错误如果条件在2月29日在php中不起作用,当我设置日期29 feb时它显示第一个conditon true1

problem between 28 and 29 February, please change date and see result

$cmncdate = '2019-02-29';

$time=strtotime($cmncdate);

$day=date("d",$time);

$mnth=date("m",$time);

if ($day>=1 AND $day<11)

    { $nday = '10'; $newDate = date("Y-m-$nday", strtotime($cmncdate)); 

    echo $newDate; }

elseif ($day>10 AND $day<21)

    { $nday = '20'; $newDate = date("Y-m-$nday", strtotime($cmncdate)); 

    echo $newDate; }

elseif ($day>20 AND $day<31 AND $mnth!=2)

    { $nday = '30';  $newDate = date("Y-m-$nday", strtotime($cmncdate)); 

    echo $newDate; }

elseif ($day>20 AND $day<29 AND $mnth=2)

    { $nday = '28'; $newDate = date("Y-m-$nday", strtotime($cmncdate)); 

    echo $newDate; }

    elseif ($day=29 AND $mnth=2)

    { $nday = '29';  $newDate = date("Y-m-$nday", strtotime($cmncdate)); 

    echo $newDate; }

The problem is that 2019-02-29 is an invalid date. The 29th is only valid on leap years (2012,2016,2020 etc.). So the date automatically rolls over to the 1/3/2019...

$cmncdate = '2019-02-29';
$time=strtotime($cmncdate);
$day=date("d",$time);
$mnth=date("m",$time);
echo $mnth.".".$day;

gives...

03.01

So try with the year 2020 instead...

$cmncdate = '2020-02-29';
$time=strtotime($cmncdate);
$day=date("d",$time);
$mnth=date("m",$time);
echo $mnth.".".$day;