3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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; }
Output for 5.3.0 - 7.1.0
Array ( [2007] => Array ( [March] => Array ( [0] => Week 12 [1] => Week 13 ) [April] => Array ( [0] => Week 14 [1] => Week 15 [2] => Week 16 [3] => Week 17 ) [May] => Array ( [0] => Week 18 [1] => Week 19 [2] => Week 20 [3] => Week 21 ) [June] => Array ( [0] => Week 22 [1] => Week 23 [2] => Week 24 [3] => Week 25 [4] => Week 26 ) [July] => Array ( [0] => Week 27 [1] => Week 28 [2] => Week 29 [3] => Week 30 ) [August] => Array ( [0] => Week 31 [1] => Week 32 [2] => Week 33 [3] => Week 34 ) [September] => Array ( [0] => Week 35 [1] => Week 36 [2] => Week 37 [3] => Week 38 [4] => Week 39 ) [October] => Array ( [0] => Week 40 [1] => Week 41 [2] => Week 42 [3] => Week 43 ) [November] => Array ( [0] => Week 44 [1] => Week 45 [2] => Week 46 [3] => Week 47 ) [December] => Array ( [0] => Week 48 [1] => Week 49 [2] => Week 50 [3] => Week 51 [4] => Week 52 ) ) [2008] => Array ( [January] => Array ( [0] => Week 01 [1] => Week 02 [2] => Week 03 [3] => Week 04 ) [February] => Array ( [0] => Week 05 [1] => Week 06 [2] => Week 07 [3] => Week 08 ) [March] => Array ( [0] => Week 09 [1] => Week 10 [2] => Week 11 [3] => Week 12 [4] => Week 13 ) [April] => Array ( [0] => Week 14 [1] => Week 15 [2] => Week 16 [3] => Week 17 ) [May] => Array ( [0] => Week 18 [1] => Week 19 [2] => Week 20 [3] => Week 21 [4] => Week 22 ) [June] => Array ( [0] => Week 23 [1] => Week 24 [2] => Week 25 [3] => Week 26 ) [July] => Array ( [0] => Week 27 [1] => Week 28 [2] => Week 29 [3] => Week 30 ) [August] => Array ( [0] => Week 31 [1] => Week 32 [2] => Week 33 [3] => Week 34 [4] => Week 35 ) [September] => Array ( [0] => Week 36 [1] => Week 37 [2] => Week 38 [3] => Week 39 ) [October] => Array ( [0] => Week 40 [1] => Week 41 [2] => Week 42 [3] => Week 43 ) [November] => Array ( [0] => Week 44 [1] => Week 45 [2] => Week 46 [3] => Week 47 [4] => Week 48 ) [December] => Array ( [0] => Week 49 [1] => Week 50 [2] => Week 51 [3] => Week 52 ) ) [2009] => Array ( [January] => Array ( [0] => Week 01 [1] => Week 02 [2] => Week 03 [3] => Week 04 [4] => Week 05 ) [February] => Array ( [0] => Week 06 [1] => Week 07 [2] => Week 08 [3] => Week 09 ) [March] => Array ( [0] => Week 10 [1] => Week 11 [2] => Week 12 [3] => Week 13 ) [April] => Array ( [0] => Week 14 [1] => Week 15 [2] => Week 16 [3] => Week 17 ) [May] => Array ( [0] => Week 18 [1] => Week 19 [2] => Week 20 [3] => Week 21 [4] => Week 22 ) [June] => Array ( [0] => Week 23 [1] => Week 24 [2] => Week 25 ) ) )
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::add() in /in/tGOqs on line 13
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/tGOqs on line 11
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/tGOqs on line 11
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/tGOqs on line 11