简体   繁体   中英

ask data's from current date to 7 days ahead and past 7 days

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM