【问题标题】:ask data's from current date to 7 days ahead and past 7 days询问从当前日期到前 7 天和过去 7 天的数据
【发布时间】:2017-08-17 13:04:38
【问题描述】:

我正在尝试每周选择一堆比赛。我怎样才能做到这一点。 它应该显示当前时间+7天和-7天的以前和新游戏的数据。

目前,我有这个

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>";        
}

问题已经解决了!对于那些有类似问题的人......希望这能有所帮助!

【问题讨论】:

  • 如您所见,标签已被编辑。这里没有 jQuery,除非你想把逻辑移到客户端
  • 谢谢罗里!编辑

标签: php string strtotime


【解决方案1】:

你几乎明白了。您可以通过以下程序方式从日期中添加/减去时间段:

$lnToday = date("d-m-Y", strtotime("+7 days"));

【讨论】:

  • 仍在获取所有游戏的列表。我究竟做错了什么?我已经编辑了到目前为止的内容。 ..我还需要一个开始时间结束时间吗?
  • 很抱歉听到这个消息。 $loMatch-&gt;Date 返回什么?
  • 我很高兴听到这个消息。
猜你喜欢
  • 2012-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-25
  • 2015-06-11
  • 1970-01-01
相关资源
最近更新 更多