kkochanski kkochanski - 1 year ago 101
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?

Answer Source

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']));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download