function DateRange ($begin,$end,$interval='M'){ $begin = new DateTime($begin); $end = new DateTime($end); $end = $end->modify('+1 day'); $t ='P1'.$interval; $interval = new DateInterval($t); $daterange = new DatePeriod($begin, $interval ,$end); foreach($daterange as $date){ $range[]= $date->format("Ymd"); } return $range; }