3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function countDaysByName($dayName, \DateTime $start, \DateTime $end) { $count = 0; $interval = new \DateInterval('P1D'); $period = new \DatePeriod($start, $interval, $end); foreach($period as $day){ if($day->format('D') === ucfirst(substr($dayName, 0, 3))){ $count ++; } } return $count; } echo countDaysByName('wednesday', new \DateTime(2016-01-18), new \DateTime(2016-01-23)); echo var_dump(new \DateTime(2016-01-18));
based on pHgp2
Output for 7.0.20 - 7.2.11
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-01-16 13:28:21.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.6
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-05-21 13:54:02.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.5
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-04-03 09:50:48.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.4
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-03-10 21:58:18.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.3
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-03-18 23:26:22.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.2
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-03-23 05:40:15.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.1
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-03-24 08:43:05.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.0
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-03-27 10:36:03.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.28
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-01-16 13:28:21.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.21
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-05-02 16:45:16.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.20
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-10 08:53:10.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.19
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-08 06:08:14.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.18
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-15 15:06:43.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.17
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-20 02:38:51.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.16
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-28 11:25:54.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.15
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-29 12:15:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.14
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-14 17:57:54.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.13
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-15 18:36:47.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.12
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-20 09:07:10.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.11
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-24 15:33:09.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.10
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-25 17:38:47.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.9
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-27 23:06:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.8
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-30 07:33:30.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.35
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-05-23 02:49:47.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.34
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-11 11:08:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.33
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-09 09:07:53.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.32
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-17 19:05:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.31
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-21 05:51:22.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.30
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-01 14:06:54.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.29
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-17 08:54:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.28
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-21 12:26:42.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.27
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-22 14:04:25.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.26
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-26 20:20:13.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.25
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-29 03:46:47.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.24
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-05-24 16:52:20.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.45
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-01-16 13:28:24.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.44
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-01-16 13:28:25.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.42 - 5.4.43
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-01-16 13:28:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.40 - 5.4.41
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-01-16 13:28:27.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.38 - 5.4.39
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-01-16 13:28:28.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.36 - 5.4.37
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-01-16 13:28:29.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.34 - 5.4.35
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-01-16 13:28:30.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.31 - 5.4.32
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-01-16 13:28:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.30
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-01-16 13:28:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.28 - 5.4.29
0object(DateTime)#1 (3) { ["date"]=> string(19) "1997-01-16 13:28:32" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.25 - 5.4.27
0object(DateTime)#1 (3) { ["date"]=> string(19) "1997-01-16 13:28:33" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.3.28, 5.4.21 - 5.4.24
0object(DateTime)#1 (3) { ["date"]=> string(19) "1997-01-16 13:28:34" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.19 - 5.4.20
0object(DateTime)#1 (3) { ["date"]=> string(19) "1997-01-16 13:28:35" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.3.26 - 5.3.27, 5.4.17 - 5.4.18
0object(DateTime)#1 (3) { ["date"]=> string(19) "1997-01-16 13:28:36" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.3.23 - 5.3.25, 5.4.13 - 5.4.16
0object(DateTime)#1 (3) { ["date"]=> string(19) "1997-01-16 13:28:37" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.3.21 - 5.3.22, 5.4.11 - 5.4.12
0object(DateTime)#1 (3) { ["date"]=> string(19) "1997-01-16 13:28:38" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.3.29
0object(DateTime)#1 (3) { ["date"]=> string(19) "1997-01-16 13:28:31" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }