Error If condition not working for 29 February in php , when i set date 29 feb it show first conditon true1

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Error If condition not working for 29 February in php , when i set date 29 feb it show first 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;





It would be better if you post the result yourself in the post and write exactly what happens in the code when executed.
– Shai
Aug 12 at 7:28




1 Answer
1



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...


2019-02-29


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;






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard