0

Can someone help me with this please. Trying to calculate week dates within a period entered by the user. How would I go about that? I have this thus far

$interval=new DateInterval('P6D');
        $period = new DatePeriod($begindate,$interval,$enddate);


     foreach($period as $date){
     echo $date->format("Y/m/d") . "<br>";
    }

    if ($period){

        return true;
    }
    else {
        return false;
    }

2017/08/06 2017/08/12 2017/08/18 The first two outputs are ok but rather than 2017/08/18, I would like 2017/08/13 2017/08/19 and even though they are in the database its still giving the error message that it is not there

2 Answers2

0

You could itarate dates with DateInterval class

UPD

get all sundays

$start = new DateTime('2018-08-06');
$end   = new DateTime('2018-09-06');
$interval = DateInterval::createFromDateString('7 day');
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $dt)
{
    echo $dt->format('Y-m-d') . '<br>';
}

Your question about the dates or about the search in the database? Please specify

artemiuz
  • 444
  • 5
  • 7
0

You can try this:

$firstDayOfWeek = $dateTime->modify('Monday this week');
$lastDayOfWeek = $dateTime->modify('Sunday this week');
  • I have edited my question with what I have. Can you help me to edit it to have that –  Aug 03 '17 at 17:12