3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $dow = 'saturday'; $step = 2; $unit = 'W'; $start = new DateTime(); $end = clone $start; $start->modify($dow); // Move to first occurence $end->add(new DateInterval('P1Y')); // Move to 1 year from start $interval = new DateInterval("P{$step}{$unit}"); $period = new DatePeriod($start, $interval, $end); foreach ($period as $date) { echo $date->format('D, d M Y'), PHP_EOL; }
based on Zuqn8
Output for 5.6.28, 7.0.14 - 7.1.0
Sat, 01 Nov 2014 Sat, 15 Nov 2014 Sat, 29 Nov 2014 Sat, 13 Dec 2014 Sat, 27 Dec 2014 Sat, 10 Jan 2015 Sat, 24 Jan 2015 Sat, 07 Feb 2015 Sat, 21 Feb 2015 Sat, 07 Mar 2015 Sat, 21 Mar 2015 Sat, 04 Apr 2015 Sat, 18 Apr 2015 Sat, 02 May 2015 Sat, 16 May 2015 Sat, 30 May 2015 Sat, 13 Jun 2015 Sat, 27 Jun 2015 Sat, 11 Jul 2015 Sat, 25 Jul 2015 Sat, 08 Aug 2015 Sat, 22 Aug 2015 Sat, 05 Sep 2015 Sat, 19 Sep 2015 Sat, 03 Oct 2015 Sat, 17 Oct 2015 Sat, 31 Oct 2015
Output for 5.6.21, 7.0.6
Sat, 07 May 2016 Sat, 21 May 2016 Sat, 04 Jun 2016 Sat, 18 Jun 2016 Sat, 02 Jul 2016 Sat, 16 Jul 2016 Sat, 30 Jul 2016 Sat, 13 Aug 2016 Sat, 27 Aug 2016 Sat, 10 Sep 2016 Sat, 24 Sep 2016 Sat, 08 Oct 2016 Sat, 22 Oct 2016 Sat, 05 Nov 2016 Sat, 19 Nov 2016 Sat, 03 Dec 2016 Sat, 17 Dec 2016 Sat, 31 Dec 2016 Sat, 14 Jan 2017 Sat, 28 Jan 2017 Sat, 11 Feb 2017 Sat, 25 Feb 2017 Sat, 11 Mar 2017 Sat, 25 Mar 2017 Sat, 08 Apr 2017 Sat, 22 Apr 2017
Output for 5.5.30, 5.6.14, 7.0.5
Sat, 02 Apr 2016 Sat, 16 Apr 2016 Sat, 30 Apr 2016 Sat, 14 May 2016 Sat, 28 May 2016 Sat, 11 Jun 2016 Sat, 25 Jun 2016 Sat, 09 Jul 2016 Sat, 23 Jul 2016 Sat, 06 Aug 2016 Sat, 20 Aug 2016 Sat, 03 Sep 2016 Sat, 17 Sep 2016 Sat, 01 Oct 2016 Sat, 15 Oct 2016 Sat, 29 Oct 2016 Sat, 12 Nov 2016 Sat, 26 Nov 2016 Sat, 10 Dec 2016 Sat, 24 Dec 2016 Sat, 07 Jan 2017 Sat, 21 Jan 2017 Sat, 04 Feb 2017 Sat, 18 Feb 2017 Sat, 04 Mar 2017 Sat, 18 Mar 2017 Sat, 01 Apr 2017
Output for 5.5.33, 5.6.19, 7.0.4
Sat, 12 Mar 2016 Sat, 26 Mar 2016 Sat, 09 Apr 2016 Sat, 23 Apr 2016 Sat, 07 May 2016 Sat, 21 May 2016 Sat, 04 Jun 2016 Sat, 18 Jun 2016 Sat, 02 Jul 2016 Sat, 16 Jul 2016 Sat, 30 Jul 2016 Sat, 13 Aug 2016 Sat, 27 Aug 2016 Sat, 10 Sep 2016 Sat, 24 Sep 2016 Sat, 08 Oct 2016 Sat, 22 Oct 2016 Sat, 05 Nov 2016 Sat, 19 Nov 2016 Sat, 03 Dec 2016 Sat, 17 Dec 2016 Sat, 31 Dec 2016 Sat, 14 Jan 2017 Sat, 28 Jan 2017 Sat, 11 Feb 2017 Sat, 25 Feb 2017
Output for 5.6.17, 7.0.3
Sat, 19 Mar 2016 Sat, 02 Apr 2016 Sat, 16 Apr 2016 Sat, 30 Apr 2016 Sat, 14 May 2016 Sat, 28 May 2016 Sat, 11 Jun 2016 Sat, 25 Jun 2016 Sat, 09 Jul 2016 Sat, 23 Jul 2016 Sat, 06 Aug 2016 Sat, 20 Aug 2016 Sat, 03 Sep 2016 Sat, 17 Sep 2016 Sat, 01 Oct 2016 Sat, 15 Oct 2016 Sat, 29 Oct 2016 Sat, 12 Nov 2016 Sat, 26 Nov 2016 Sat, 10 Dec 2016 Sat, 24 Dec 2016 Sat, 07 Jan 2017 Sat, 21 Jan 2017 Sat, 04 Feb 2017 Sat, 18 Feb 2017 Sat, 04 Mar 2017 Sat, 18 Mar 2017
Output for 5.5.31, 7.0.1 - 7.0.2
Sat, 26 Mar 2016 Sat, 09 Apr 2016 Sat, 23 Apr 2016 Sat, 07 May 2016 Sat, 21 May 2016 Sat, 04 Jun 2016 Sat, 18 Jun 2016 Sat, 02 Jul 2016 Sat, 16 Jul 2016 Sat, 30 Jul 2016 Sat, 13 Aug 2016 Sat, 27 Aug 2016 Sat, 10 Sep 2016 Sat, 24 Sep 2016 Sat, 08 Oct 2016 Sat, 22 Oct 2016 Sat, 05 Nov 2016 Sat, 19 Nov 2016 Sat, 03 Dec 2016 Sat, 17 Dec 2016 Sat, 31 Dec 2016 Sat, 14 Jan 2017 Sat, 28 Jan 2017 Sat, 11 Feb 2017 Sat, 25 Feb 2017 Sat, 11 Mar 2017
Output for 7.0.0
Sat, 26 Mar 2016 Sat, 09 Apr 2016 Sat, 23 Apr 2016 Sat, 07 May 2016 Sat, 21 May 2016 Sat, 04 Jun 2016 Sat, 18 Jun 2016 Sat, 02 Jul 2016 Sat, 16 Jul 2016 Sat, 30 Jul 2016 Sat, 13 Aug 2016 Sat, 27 Aug 2016 Sat, 10 Sep 2016 Sat, 24 Sep 2016 Sat, 08 Oct 2016 Sat, 22 Oct 2016 Sat, 05 Nov 2016 Sat, 19 Nov 2016 Sat, 03 Dec 2016 Sat, 17 Dec 2016 Sat, 31 Dec 2016 Sat, 14 Jan 2017 Sat, 28 Jan 2017 Sat, 11 Feb 2017 Sat, 25 Feb 2017 Sat, 11 Mar 2017 Sat, 25 Mar 2017
Output for 5.6.15 - 5.6.16, hhvm-3.12.0
Sat, 02 Apr 2016 Sat, 16 Apr 2016 Sat, 30 Apr 2016 Sat, 14 May 2016 Sat, 28 May 2016 Sat, 11 Jun 2016 Sat, 25 Jun 2016 Sat, 09 Jul 2016 Sat, 23 Jul 2016 Sat, 06 Aug 2016 Sat, 20 Aug 2016 Sat, 03 Sep 2016 Sat, 17 Sep 2016 Sat, 01 Oct 2016 Sat, 15 Oct 2016 Sat, 29 Oct 2016 Sat, 12 Nov 2016 Sat, 26 Nov 2016 Sat, 10 Dec 2016 Sat, 24 Dec 2016 Sat, 07 Jan 2017 Sat, 21 Jan 2017 Sat, 04 Feb 2017 Sat, 18 Feb 2017 Sat, 04 Mar 2017 Sat, 18 Mar 2017
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.6.20
Sat, 09 Apr 2016 Sat, 23 Apr 2016 Sat, 07 May 2016 Sat, 21 May 2016 Sat, 04 Jun 2016 Sat, 18 Jun 2016 Sat, 02 Jul 2016 Sat, 16 Jul 2016 Sat, 30 Jul 2016 Sat, 13 Aug 2016 Sat, 27 Aug 2016 Sat, 10 Sep 2016 Sat, 24 Sep 2016 Sat, 08 Oct 2016 Sat, 22 Oct 2016 Sat, 05 Nov 2016 Sat, 19 Nov 2016 Sat, 03 Dec 2016 Sat, 17 Dec 2016 Sat, 31 Dec 2016 Sat, 14 Jan 2017 Sat, 28 Jan 2017 Sat, 11 Feb 2017 Sat, 25 Feb 2017 Sat, 11 Mar 2017 Sat, 25 Mar 2017 Sat, 08 Apr 2017
Output for 5.5.32, 5.6.18
Sat, 19 Mar 2016 Sat, 02 Apr 2016 Sat, 16 Apr 2016 Sat, 30 Apr 2016 Sat, 14 May 2016 Sat, 28 May 2016 Sat, 11 Jun 2016 Sat, 25 Jun 2016 Sat, 09 Jul 2016 Sat, 23 Jul 2016 Sat, 06 Aug 2016 Sat, 20 Aug 2016 Sat, 03 Sep 2016 Sat, 17 Sep 2016 Sat, 01 Oct 2016 Sat, 15 Oct 2016 Sat, 29 Oct 2016 Sat, 12 Nov 2016 Sat, 26 Nov 2016 Sat, 10 Dec 2016 Sat, 24 Dec 2016 Sat, 07 Jan 2017 Sat, 21 Jan 2017 Sat, 04 Feb 2017 Sat, 18 Feb 2017 Sat, 04 Mar 2017
Output for 5.5.29, 5.6.13
Sat, 16 Apr 2016 Sat, 30 Apr 2016 Sat, 14 May 2016 Sat, 28 May 2016 Sat, 11 Jun 2016 Sat, 25 Jun 2016 Sat, 09 Jul 2016 Sat, 23 Jul 2016 Sat, 06 Aug 2016 Sat, 20 Aug 2016 Sat, 03 Sep 2016 Sat, 17 Sep 2016 Sat, 01 Oct 2016 Sat, 15 Oct 2016 Sat, 29 Oct 2016 Sat, 12 Nov 2016 Sat, 26 Nov 2016 Sat, 10 Dec 2016 Sat, 24 Dec 2016 Sat, 07 Jan 2017 Sat, 21 Jan 2017 Sat, 04 Feb 2017 Sat, 18 Feb 2017 Sat, 04 Mar 2017 Sat, 18 Mar 2017 Sat, 01 Apr 2017 Sat, 15 Apr 2017
Output for 5.5.28, 5.6.12
Sat, 23 Apr 2016 Sat, 07 May 2016 Sat, 21 May 2016 Sat, 04 Jun 2016 Sat, 18 Jun 2016 Sat, 02 Jul 2016 Sat, 16 Jul 2016 Sat, 30 Jul 2016 Sat, 13 Aug 2016 Sat, 27 Aug 2016 Sat, 10 Sep 2016 Sat, 24 Sep 2016 Sat, 08 Oct 2016 Sat, 22 Oct 2016 Sat, 05 Nov 2016 Sat, 19 Nov 2016 Sat, 03 Dec 2016 Sat, 17 Dec 2016 Sat, 31 Dec 2016 Sat, 14 Jan 2017 Sat, 28 Jan 2017 Sat, 11 Feb 2017 Sat, 25 Feb 2017 Sat, 11 Mar 2017 Sat, 25 Mar 2017 Sat, 08 Apr 2017
Output for 5.5.27, 5.6.11
Sat, 23 Apr 2016 Sat, 07 May 2016 Sat, 21 May 2016 Sat, 04 Jun 2016 Sat, 18 Jun 2016 Sat, 02 Jul 2016 Sat, 16 Jul 2016 Sat, 30 Jul 2016 Sat, 13 Aug 2016 Sat, 27 Aug 2016 Sat, 10 Sep 2016 Sat, 24 Sep 2016 Sat, 08 Oct 2016 Sat, 22 Oct 2016 Sat, 05 Nov 2016 Sat, 19 Nov 2016 Sat, 03 Dec 2016 Sat, 17 Dec 2016 Sat, 31 Dec 2016 Sat, 14 Jan 2017 Sat, 28 Jan 2017 Sat, 11 Feb 2017 Sat, 25 Feb 2017 Sat, 11 Mar 2017 Sat, 25 Mar 2017 Sat, 08 Apr 2017 Sat, 22 Apr 2017
Output for 5.5.25 - 5.5.26, 5.6.9 - 5.6.10
Sat, 30 Apr 2016 Sat, 14 May 2016 Sat, 28 May 2016 Sat, 11 Jun 2016 Sat, 25 Jun 2016 Sat, 09 Jul 2016 Sat, 23 Jul 2016 Sat, 06 Aug 2016 Sat, 20 Aug 2016 Sat, 03 Sep 2016 Sat, 17 Sep 2016 Sat, 01 Oct 2016 Sat, 15 Oct 2016 Sat, 29 Oct 2016 Sat, 12 Nov 2016 Sat, 26 Nov 2016 Sat, 10 Dec 2016 Sat, 24 Dec 2016 Sat, 07 Jan 2017 Sat, 21 Jan 2017 Sat, 04 Feb 2017 Sat, 18 Feb 2017 Sat, 04 Mar 2017 Sat, 18 Mar 2017 Sat, 01 Apr 2017 Sat, 15 Apr 2017
Output for 5.6.8
Sat, 30 Apr 2016 Sat, 14 May 2016 Sat, 28 May 2016 Sat, 11 Jun 2016 Sat, 25 Jun 2016 Sat, 09 Jul 2016 Sat, 23 Jul 2016 Sat, 06 Aug 2016 Sat, 20 Aug 2016 Sat, 03 Sep 2016 Sat, 17 Sep 2016 Sat, 01 Oct 2016 Sat, 15 Oct 2016 Sat, 29 Oct 2016 Sat, 12 Nov 2016 Sat, 26 Nov 2016 Sat, 10 Dec 2016 Sat, 24 Dec 2016 Sat, 07 Jan 2017 Sat, 21 Jan 2017 Sat, 04 Feb 2017 Sat, 18 Feb 2017 Sat, 04 Mar 2017 Sat, 18 Mar 2017 Sat, 01 Apr 2017 Sat, 15 Apr 2017 Sat, 29 Apr 2017
Output for 5.5.24, 5.5.35 - 5.6.7
Sat, 28 May 2016 Sat, 11 Jun 2016 Sat, 25 Jun 2016 Sat, 09 Jul 2016 Sat, 23 Jul 2016 Sat, 06 Aug 2016 Sat, 20 Aug 2016 Sat, 03 Sep 2016 Sat, 17 Sep 2016 Sat, 01 Oct 2016 Sat, 15 Oct 2016 Sat, 29 Oct 2016 Sat, 12 Nov 2016 Sat, 26 Nov 2016 Sat, 10 Dec 2016 Sat, 24 Dec 2016 Sat, 07 Jan 2017 Sat, 21 Jan 2017 Sat, 04 Feb 2017 Sat, 18 Feb 2017 Sat, 04 Mar 2017 Sat, 18 Mar 2017 Sat, 01 Apr 2017 Sat, 15 Apr 2017 Sat, 29 Apr 2017 Sat, 13 May 2017
Output for 5.5.34
Sat, 16 Apr 2016 Sat, 30 Apr 2016 Sat, 14 May 2016 Sat, 28 May 2016 Sat, 11 Jun 2016 Sat, 25 Jun 2016 Sat, 09 Jul 2016 Sat, 23 Jul 2016 Sat, 06 Aug 2016 Sat, 20 Aug 2016 Sat, 03 Sep 2016 Sat, 17 Sep 2016 Sat, 01 Oct 2016 Sat, 15 Oct 2016 Sat, 29 Oct 2016 Sat, 12 Nov 2016 Sat, 26 Nov 2016 Sat, 10 Dec 2016 Sat, 24 Dec 2016 Sat, 07 Jan 2017 Sat, 21 Jan 2017 Sat, 04 Feb 2017 Sat, 18 Feb 2017 Sat, 04 Mar 2017 Sat, 18 Mar 2017 Sat, 01 Apr 2017
Output for 5.3.0 - 5.4.45
Sat, 07 Nov 2015 Sat, 21 Nov 2015 Sat, 05 Dec 2015 Sat, 19 Dec 2015 Sat, 02 Jan 2016 Sat, 16 Jan 2016 Sat, 30 Jan 2016 Sat, 13 Feb 2016 Sat, 27 Feb 2016 Sat, 12 Mar 2016 Sat, 26 Mar 2016 Sat, 09 Apr 2016 Sat, 23 Apr 2016 Sat, 07 May 2016 Sat, 21 May 2016 Sat, 04 Jun 2016 Sat, 18 Jun 2016 Sat, 02 Jul 2016 Sat, 16 Jul 2016 Sat, 30 Jul 2016 Sat, 13 Aug 2016 Sat, 27 Aug 2016 Sat, 10 Sep 2016 Sat, 24 Sep 2016 Sat, 08 Oct 2016 Sat, 22 Oct 2016
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::add() in /in/cILfK on line 10
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/cILfK on line 6
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_VARIABLE in /in/cILfK on line 7
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_VARIABLE in /in/cILfK on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/cILfK on line 7
Process exited with code 255.