doujianwan7570 2015-12-14 12:11
浏览 9
已采纳

从输出中排除从星期六开始的周数

I have this script which displays the start date an end date for each week in a month.

I would like to somehow filter out the first week that may start with Saturday.. For example if we take August 2015 as an example, the first week

<?php       
$textdt="01 Aug 2015";
$dt= strtotime( $textdt);
$currdt=$dt;
$nextmonth=strtotime($textdt."+1 month");
$i=0;
do 
{
    $weekday= date("w",$currdt);
    $nextday=7-$weekday;
    $endday=abs($weekday-7);
    $startarr[$i]=$currdt;
    $endarr[$i]=strtotime(date("Y-m-d",$currdt)."+$endday day");
    $currdt=strtotime(date("Y-m-d",$endarr[$i])."+1 day");
    echo "Week ".($i+1)." - ". date("d-m-Y",$startarr[$i])." to ". date("d-m-Y",$endarr[$i])."<br>";
     $i++;

}while($endarr[$i-1]<$nextmonth);
?>

Current output

Week 1 - 01-08-2015 to 02-08-2015
Week 2 - 03-08-2015 to 09-08-2015
Week 3 - 10-08-2015 to 16-08-2015
Week 4 - 17-08-2015 to 23-08-2015
Week 5 - 24-08-2015 to 30-08-2015
Week 6 - 31-08-2015 to 06-09-2015

Desired output

Week 1 - 03-08-2015 to 09-08-2015
Week 2 - 10-08-2015 to 16-08-2015
Week 3 - 17-08-2015 to 23-08-2015
Week 4 - 24-08-2015 to 30-08-2015
Week 5 - 31-08-2015 to 06-09-2015
  • 写回答

2条回答 默认 最新

  • duanci19881003 2015-12-14 12:25
    关注

    Just check date("D",$startarr[$i]) !== "Sat" or you can use if($weekday != 6)

    if(date("D",$startarr[$i]) !== "Sat") {
        echo "Week ".($i+1)." - ". date("d-m-Y",$startarr[$i])." to ". date("d-m-Y",$endarr[$i])."<br>";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据