dougou5844 2018-08-12 06:18
浏览 40
已采纳

错误如果条件在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; }
  • 写回答

1条回答 默认 最新

  • doudou1897 2018-08-12 06:42
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口