doudao3170 2016-03-10 07:47
浏览 54
已采纳

Codeigniter - 计算两个日期之间的日期

I have a simple table with Location, Start Date and End Date.

These are school terms so the range is about 12 to 14 weeks and don't cross the end of year.

I need to calculate and display all the dates (dd/mm) of the Mondays between the dates?

The start and end date may or may not be Mondays.

  • 写回答

3条回答 默认 最新

  • douyudouchao6779 2016-03-10 09:15
    关注

    You can try converting the datestart and end then for loop them. As you loop them use the date() to check if it is Monday. date() manual is here.

    <?php
    $date_from = strtotime("2016-03-01");
    $date_to = strtotime("2016-04-30");
    
    $oneDay = 60*60*24;
    
    for($i=$date_from; $i<=$date_to; $i=$i+$oneDay)
    {
        if (date('N', $i) == 1) { //date('N') 1 = Monday, 2 = Tuesday....
            echo date("D", $i) ." ". date('Y-m-d', $i) ."<br>";
        }
    }
    ?>
    

    Output:

    Mon 2016-03-07
    Mon 2016-03-14
    Mon 2016-03-21
    Mon 2016-03-28
    Mon 2016-04-04
    Mon 2016-04-11
    Mon 2016-04-18
    Mon 2016-04-25
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助