3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start_date = '2007-03-24'; $end_date = '2009-06-26'; print_r(year_month($start_date, $end_date)); //Returns an array containing the years, months and days between two dates function year_month($start_date, $end_date) { $begin = new DateTime( $start_date ); $end = new DateTime( $end_date); $end->add(new DateInterval('P1D')); //Add 1 day to include the end date as a day $interval = new DateInterval('P1W'); //Add 1 week $period = new DatePeriod($begin, $interval, $end); $aResult = array(); foreach ( $period as $dt ) { $aResult[$dt->format('Y')][$dt->format('F')][] = "Week ".$dt->format('W'); } return $aResult; }

preferences:
42.96 ms | 402 KiB | 5 Q