3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $firstAvailableCount = 100; $slice = 'monthly'; $countData = array(); $startDateTime = new DateTime("2016-01-07"); $endDateTime = new DateTime("2016-02-02"); fillCountMapPeriod($startDateTime,$endDateTime,$countData,$firstAvailableCount,$slice); function fillCountMapPeriod( DateTime $startDateTime, DateTime $endDateTime, array $countData, $firstAvailableCount, $slice) { if($slice == 'monthly') { $interval = new DateInterval('P1M'); $format = 'm-Y'; $startDateTime = DateTime::createFromFormat($format."-d",$startDateTime->format($format).-"1"); $endDateTime = DateTime::createFromFormat($format."-d",$endDateTime->format($format).-"1"); } else { $interval = new DateInterval('P1W'); $format = 'W-Y'; } var_dump($startDateTime); if($startDateTime->format($format) == $endDateTime->format($format)) { var_dump($startDateTime->format($format)); return; } $endDateTime->add($interval); //var_dump($endDateTime); while($startDateTime <= $endDateTime){ var_dump($startDateTime->format("d-".$format)); $startDateTime->add($interval); } }
based on BYecF
Output for 5.6.28, 7.0.20 - 7.2.0
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:51:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 7.0.6
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 13:22:34.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 7.0.5
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 09:24:42.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 7.0.4
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 21:31:09.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 7.0.3
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 22:55:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 7.0.2
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 05:08:21.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 7.0.1
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:15:35.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 7.0.0
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 10:08:53.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.21
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 16:17:41.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.20
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:26:34.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.19
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 05:39:24.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.18
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 14:36:29.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.17
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 02:08:45.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.16
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 10:58:09.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.15
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 11:47:27.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.14
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 17:30:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.13
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 18:09:04.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.12
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:38:03.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.11
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 15:04:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.10
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 17:10:03.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.9
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 22:36:02.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.6.8
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 07:06:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.35
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 02:15:37.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.34
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 10:40:24.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.33
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:38:13.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.32
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 18:33:03.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.31
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 05:17:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.30
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 13:39:34.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.29
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:26:45.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.28
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 11:56:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.27
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 13:35:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.26
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:50:42.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.25
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 03:16:02.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.24
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 09:39:25.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.4.45
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:01.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.4.44
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:02.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.4.41 - 5.4.43
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:03.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.4.38 - 5.4.40
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:04.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.4.34 - 5.4.37
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:05.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.4.30 - 5.4.32
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.3.29, 5.4.29
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:52:06" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.4.23 - 5.4.28
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:52:07" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.3.27 - 5.3.28, 5.4.18 - 5.4.22
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:52:08" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.3.22 - 5.3.26, 5.4.12 - 5.4.17
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:52:09" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.3.21, 5.4.11
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:52:10" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"