dpwtr666638 2013-04-16 12:41
浏览 434

在php中的两个日期之间获取周数

I want to get the week numbers for given two dates i.e from 2012-01-01 to 2012-12-31.The week numbers should fall exactly in the range as specified above.Can u please give suggestions for doing this.

  • 写回答

5条回答 默认 最新

  • dpgjci27392 2013-04-16 12:44
    关注

    Something like this should work fine:

    <?php
        $startDateUnix = strtotime('2012-01-01');
        $endDateUnix = strtotime('2013-01-01');
    
        $currentDateUnix = $startDateUnix;
    
        $weekNumbers = array();
        while ($currentDateUnix < $endDateUnix) {
            $weekNumbers[] = date('W', $currentDateUnix);
            $currentDateUnix = strtotime('+1 week', $currentDateUnix);
        }
    
        print_r($weekNumbers);
    ?>
    

    DEMO.

    Output:

    Array
    (
        [0] => 52
        [1] => 01
        [2] => 02
        .........
        [51] => 51
        [52] => 52
    )
    
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记