3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function getDay($day) { $days = ['Monday' => 1, 'Tuesday' => 2, 'Wednesday' => 3, 'Thursday' => 4, 'Friday' => 5, 'Saturday' => 6, 'Sunday' => 7]; $today = new \DateTime(); $today->setISODate((int)$today->format('o'), (int)$today->format('W'), $days[ucfirst($day)]); return $today; } var_dump(getDay('Monday')->setTime(0, 0, 0)->format('Y-m-d H:i:s')); var_dump(getDay('Friday'));
based on kfSRj
Output for 7.2.0
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:20.004137" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.1.10
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:20.004496" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.1.7
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:20.005954" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.1.6
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:20.012592" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.1.5
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:20.011358" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.1.0
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:20.004312" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.28, 7.0.20
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:20.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.6
string(19) "2016-05-16 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-05-20 14:20:56.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.5
string(19) "2016-03-28 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-01 10:13:17.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.4
string(19) "2016-03-07 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-11 22:22:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.3
string(19) "2016-03-14 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-18 23:57:53.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.2
string(19) "2016-03-21 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-25 06:04:56.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.1
string(19) "2016-03-21 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-25 09:06:58.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.0
string(19) "2016-03-21 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-25 10:58:07.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.21
string(19) "2016-05-02 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-05-06 17:08:20.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.20
string(19) "2016-04-04 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-08 09:15:19.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.19
string(19) "2016-03-07 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-11 06:31:25.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.18
string(19) "2016-03-14 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-18 15:31:48.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.17
string(19) "2016-03-14 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-18 03:09:51.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.16
string(19) "2016-03-28 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-01 11:47:56.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.15
string(19) "2016-03-28 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-01 12:37:43.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.14
string(19) "2016-04-11 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-15 18:20:42.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.13
string(19) "2016-04-11 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-15 18:59:45.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.12
string(19) "2016-04-18 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-22 09:30:54.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.11
string(19) "2016-04-18 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-22 15:56:53.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.10
string(19) "2016-04-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-29 18:02:14.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.9
string(19) "2016-04-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-29 23:31:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.8
string(19) "2016-04-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-29 07:57:07.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.35
string(19) "2016-05-23 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-05-27 03:23:10.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.34
string(19) "2016-04-11 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-15 11:29:45.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.33
string(19) "2016-03-07 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-11 09:36:44.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.32
string(19) "2016-03-14 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-18 19:32:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.31
string(19) "2016-03-21 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-25 06:19:41.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.30
string(19) "2016-03-28 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-01 14:28:38.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.29
string(19) "2016-04-11 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-15 09:17:01.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.28
string(19) "2016-04-18 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-22 12:51:03.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.27
string(19) "2016-04-18 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-22 14:27:09.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.26
string(19) "2016-04-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-29 20:44:23.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.25
string(19) "2016-04-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-29 04:12:09.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.24
string(19) "2016-05-23 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-05-27 10:42:40.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.45
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:23.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.42 - 5.4.44
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:24.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.40 - 5.4.41
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:25.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.38 - 5.4.39
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.34 - 5.4.37
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:27.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.30 - 5.4.32
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:41:28.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.29
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(19) "2016-01-29 23:41:28" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.23 - 5.4.28
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(19) "2016-01-29 23:41:29" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.18 - 5.4.22
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(19) "2016-01-29 23:41:30" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.13 - 5.4.17
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(19) "2016-01-29 23:41:31" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.12
string(19) "2016-01-25 00:00:00" object(DateTime)#1 (3) { ["date"]=> string(19) "2016-01-29 23:41:32" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.3.22 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/MBd6S on line 4
Process exited with code 255.