Donny Abraham Donny Abraham - 1 month ago 10
PHP Question

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 (){
$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"] : "",
isset($_GET["DateFrom"]) ? $_GET["DateFrom"] : "",
isset($_GET["DateTo"]) ? $_GET["DateTo"] : "",
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 = strtotime(date("d-m-Y"));
$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>";
}


I think I need to do this?

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


can somebody help me. thx again!

Answer Source

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