3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php print_r(getPeroid()); // Example 1 print_r(getPeroid()->start); // Example 3 print_r(getPeroid(new DateTime("2013-02-14"))); // Example 2 function getPeroid(\Datetime $date = null, DateInterval $interval = null) { $interval = $interval ? : new DateInterval('P7D'); $end = $date ? : new DateTime(); $end->modify("Last Sunday"); $start = clone $end; $start->sub($interval); return (object) array( "start" => $start->format("l, d F Y"), "end" => $end->format("l, d F Y") ); } function getPeriodBetween(Datetime $start = null, Datetime $end = null, DateInterval $interval = null) { $interval = $interval ? : new DateInterval('P7D'); if ($start === null) { $start = new DateTime(); $start->modify("First Sunday of January"); } else { $start->modify("First Sunday"); } if ($end === null) { $end = new DateTime(); $end->modify("Last Sunday of December"); } $range = array(); while ( $start < $end ) { $r = (object) array( "start" => $start->format("l, d F Y") ); $start->add($interval); $r->end = $start->format("l, d F Y"); $range[] = $r; } return $range; }
Output for 7.0.12 - 7.1.0
stdClass Object ( [start] => Sunday, 31 March 2013 [end] => Sunday, 07 April 2013 ) Sunday, 31 March 2013stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 7.0.6
stdClass Object ( [start] => Sunday, 24 April 2016 [end] => Sunday, 01 May 2016 ) Sunday, 24 April 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.5.30, 5.6.14 - 5.6.15, hhvm-3.10.0, 7.0.5
stdClass Object ( [start] => Sunday, 20 March 2016 [end] => Sunday, 27 March 2016 ) Sunday, 20 March 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.5.33, hhvm-3.12.0, 7.0.4
stdClass Object ( [start] => Sunday, 28 February 2016 [end] => Sunday, 06 March 2016 ) Sunday, 28 February 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.5.31 - 5.5.32, 5.6.17 - 5.6.18, 7.0.3
stdClass Object ( [start] => Sunday, 06 March 2016 [end] => Sunday, 13 March 2016 ) Sunday, 06 March 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.6.16, 7.0.0 - 7.0.2
stdClass Object ( [start] => Sunday, 13 March 2016 [end] => Sunday, 20 March 2016 ) Sunday, 13 March 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.5.24 - 5.5.26, 5.6.8 - 5.6.9, 5.6.21
stdClass Object ( [start] => Sunday, 17 April 2016 [end] => Sunday, 24 April 2016 ) Sunday, 17 April 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.5.34, 5.6.20
stdClass Object ( [start] => Sunday, 27 March 2016 [end] => Sunday, 03 April 2016 ) Sunday, 27 March 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.6.19
stdClass Object ( [start] => Sunday, 21 February 2016 [end] => Sunday, 28 February 2016 ) Sunday, 21 February 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.5.29, 5.6.13
stdClass Object ( [start] => Sunday, 03 April 2016 [end] => Sunday, 10 April 2016 ) Sunday, 03 April 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.5.27 - 5.5.28, 5.6.10 - 5.6.12
stdClass Object ( [start] => Sunday, 10 April 2016 [end] => Sunday, 17 April 2016 ) Sunday, 10 April 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.6.7
stdClass Object ( [start] => Sunday, 15 May 2016 [end] => Sunday, 22 May 2016 ) Sunday, 15 May 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.5.35
stdClass Object ( [start] => Sunday, 08 May 2016 [end] => Sunday, 15 May 2016 ) Sunday, 08 May 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.3.0 - 5.4.45
stdClass Object ( [start] => Sunday, 07 February 2016 [end] => Sunday, 14 February 2016 ) Sunday, 07 February 2016stdClass Object ( [start] => Sunday, 03 February 2013 [end] => Sunday, 10 February 2013 )
Output for 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/3q9dh on line 7 Parse error: syntax error, unexpected ':' in /in/3q9dh on line 8
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/3q9dh on line 7 Parse error: parse error, unexpected ':' in /in/3q9dh on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/3q9dh on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/3q9dh on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/3q9dh on line 3
Process exited with code 255.