Advertisement
krot

DateInterval

Apr 25th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. $year=date('Y');
  2. $from = new DateTime($year.'-09-01 08:00:00');
  3. $to   = new DateTime($year.'-09-01 21:00:00');
  4. $to->modify('+52 week');
  5. $period = new DatePeriod($from, new DateInterval('P1D'), $to);
  6. $period=iterator_to_array($period);
  7. $aWeek=array();
  8. $start=false;
  9. for($i=0,$size=sizeof($period);$i<$size;++$i){
  10.     $w=$period[$i]->format('w');
  11.     $d[]=$period[$i]->format('Y-m-d H:i:s');
  12.     if(!$start)$start=$period[$i]->format('Y-m-d H:i:s');
  13.     if($w==0)$end=$period[$i]->format('Y-m-d H:i:s');
  14.     if($start && $end){
  15.         $aWeek[]=['r'=>array($start,$end),'d'=>$d];
  16.         unset($start,$end,$d);
  17.     }
  18.    
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement