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 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了