kkochanski kkochanski - 7 months ago 59
PHP Question

PHP date - get beginning and ending day of given week from format W-m-Y

I have an array of dates in format


From e.g.
I would like to get something like
20-08-2016 - 26-08-2016
. Those days from requested format, aren't real.

Any idea how to tackle it?


try this

function getStartAndEndDate($week, $year) {
  $dto = new DateTime();
  $dto->setISODate($year, $week);
  $ret['week_start'] = $dto->format('Y-m-d');
  $dto->modify('+6 days');
  $ret['week_end'] = $dto->format('Y-m-d');
  return $ret;

$week_array = getStartAndEndDate(34,2016);

echo "start date ".date('d-m-Y',strtotime($week_array['week_start'])).'<br>';
echo "End date ".date('d-m-Y',strtotime($week_array['week_end']));