douzhi1972 2017-08-17 13:04
浏览 78
已采纳

询问从当前日期到提前7天和过去7天的数据

I am trying to select a bunch of game matches per week. how can I achieve this. It supposes to show the data's from the previous and new games from current time +7 days and -7 days.

currently, I have this

function testFR (){
     $DateFrom  = new DateTime();
     $DateTo    = new DateTime();
     $DateTo->add(new DateInterval("P7D"));
    $laMatches = (array)WaterpoloAPICached::call("Matches", "getMatches", Array(
        isset($_GET["SeasonId"]) ? $_GET["SeasonId"] : "",
        isset($_GET["DepartmentId"]) ? $_GET["DepartmentId"] : "",
        isset($_GET["ClubId"]) ? $_GET["ClubId"] : "",
        isset($_GET["TeamId"]) ? $_GET["TeamId"] : "",
        isset($_GET["PoolId"]) ? $_GET["PoolId"] : "",
        date_format($DateFrom,  'd-m-Y'),
        date_format($DateTo,    'd-m-Y'),
        isset($_GET["RefereeId"]) ? $_GET["RefereeId"] : "",    
    )); 
    // Sort Matches ascending
       usort($laMatches, function($a, $b) {
                       return stringToUnix($a->Date) - stringToUnix($b->Date);
       });
/* echo "<h6 id='rcorners' style='background-color:#3db7e4; padding: 1rem; color:white;'><strong>Wedstrijden</strong></h6>"; */
    echo "<table class='hover'>";
    echo "<tbody >";        
    $lnToday = date("d-m-Y", strtotime("+7 days"));                       
                          $lcCurrent = "";                        
       foreach($laMatches as $loMatch) {
           if(stringToUnix($loMatch->Date) >= $lnToday) {
                if($lcCurrent != $loMatch->Date) {     
            echo "<thead>";
            echo "<tr >";
            echo "<th class='text-center'>";
            echo "$loMatch->Date</th>";
            echo "<th class='text-center'></th>";      
            echo "<th class='text-center'></th>";
            echo "<th class='text-center'></th>";
            echo "<th class='text-center'>Division</th>";
            echo "</tr>";                 
            echo "</tr>
                </thead>";         
                    }               
                    $lcCurrent = $loMatch->Date;                       
            echo "<tr class='text-center'>";
                echo "<td >$loMatch->Time</td>";
                echo "<td>$loMatch->HomeTeam </td>";
                echo "<td><strong><a href='..\match?MatchId=".$loMatch->Id."&Report=".$loMatch->MatchReport."'>$loMatch->ResultHome - $loMatch->ResultGuest </a></strong></td>";
                echo "<td> $loMatch->AwayTeam</td>";
                echo "<td> $loMatch->DepartmentName</td>";
            echo "</tr>";   
            }
        }      
        echo "</tbody>";
        echo "</table>";        
}

The problem has been solved! for those who's got a similar problem...hope this help!

  • 写回答

1条回答 默认 最新

  • dongyan6910 2017-08-17 13:11
    关注

    You almost got it. You can add/subtract periods of time from dates in a procedural way like this:

    $lnToday = date("d-m-Y", strtotime("+7 days"));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面