Pick up the start day and the end day of the specified week

0

Good afternoon, I'm returning from the database the number of the week in the year.

["data_hora"]=>
string(16) "19/11/2018 15:26"
["num_semana"]=>
string(2) "47"

Where in week is the week number of the year that the date 19/11/2018 is inserted. I need a way to get the first day of week 47 (Sunday) and the last day (Saturday). Anyone have any ideas how I can do this.

    
asked by anonymous 21.11.2018 / 17:02

1 answer

1

To get date of the last day (Sunday) ideone

date_default_timezone_set('Europe/Amsterdam');
$date = new DateTime();

$date->setISODate(2018, 47, 7);

echo $date->format('Y-m-d');
  

and for the first day remove the , 7 ie $date->setISODate(2018, 47);

Bonus - returning an array ideone

 function pegarInicioFimSemana($semana, $ano) { $dto = new DateTime(); $dto->setISODate($ano, $semana); $ret['primeiro_dia'] = $dto->format('d-m-Y'); $dto->modify('+6 days'); $ret['ultimo_dia'] = $dto->format('d-m-Y'); return $ret; } $semana_array = pegarInicioFimSemana(47,2018); print_r($semana_array);
    
21.11.2018 / 17:42