3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $firstAvailableCount = 100; $slice = 'monthly'; $countData = array(); $startDateTime = new DateTime("2016-01-01"); $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; } //var_dump($endDateTime); while($startDateTime <= $endDateTime){ var_dump($startDateTime->format("d-".$format)); $startDateTime->add($interval); } }
based on EejKS
Output for 5.6.28, 7.0.20 - 7.2.0
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:44.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.6
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 13:22:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.5
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 09:24:40.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.4
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 21:31:07.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.3
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 22:55:08.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.2
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 05:08:19.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.1
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:15:33.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.0
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 10:08:50.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.21
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 16:17:38.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.20
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:26:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.19
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 05:39:22.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.18
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 14:36:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.17
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 02:08:42.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.16
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 10:58:07.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.15
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 11:47:25.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.14
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 17:29:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.13
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 18:08:56.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.12
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:38:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.11
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 15:04:08.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.10
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 17:10:01.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.9
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 22:35:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.8
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 07:06:08.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.35
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 02:15:27.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.34
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 10:40:22.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.33
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:38:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.32
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 18:33:01.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.31
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 05:17:34.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.30
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 13:39:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.29
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:26:42.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.28
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 11:56:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.27
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 13:35:08.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.26
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:50:39.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.25
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 03:15:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.24
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 09:39:23.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.4.45
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:48.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.4.44
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:49.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.4.42 - 5.4.43
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:50.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.4.40 - 5.4.41
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:51.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.4.39
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:52.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.4.36 - 5.4.38
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:53.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.4.34 - 5.4.35
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:54.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.4.31 - 5.4.32
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:55.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.4.30
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:56.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.4.27 - 5.4.29
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:52:56" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.4.23 - 5.4.26
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:52:57" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.3.28, 5.4.20 - 5.4.22
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:52:58" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.3.27, 5.4.17 - 5.4.19
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:52:59" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.3.23 - 5.3.26, 5.4.13 - 5.4.16
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:53:00" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.3.21 - 5.3.22, 5.4.11 - 5.4.12
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:53:01" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.3.29
object(DateTime)#4 (3) { ["date"]=> string(19) "2016-01-01 19:52:55" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"