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')->format('Y-m-d H:i:s')); var_dump(getDay('Friday'));
based on ogJUh
Output for 7.2.0
string(19) "2016-01-25 23:39:40" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:40.004342" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.1.10
string(19) "2016-01-25 23:39:40" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:40.003914" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.1.7
string(19) "2016-01-25 23:39:40" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:40.002778" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.1.6
string(19) "2016-01-25 23:39:40" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:40.013562" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.1.5
string(19) "2016-01-25 23:39:40" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:40.011212" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.1.0
string(19) "2016-01-25 23:39:40" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:40.003959" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.28, 7.0.20
string(19) "2016-01-25 23:39:40" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:40.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.6
string(19) "2016-05-16 14:20:56" 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 10:13:17" 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 22:22:05" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-11 22:22:05.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.3
string(19) "2016-03-14 23:57:52" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-18 23:57:52.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.2
string(19) "2016-03-21 06:04:56" 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 09:06:58" 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 10:58:07" 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 17:08:20" 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 09:15:19" 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 06:31:25" 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 15:31:48" 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 03:09:51" 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 11:47:56" 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 12:37:42" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-01 12:37:42.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.14
string(19) "2016-04-11 18:20:41" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-15 18:20:41.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.13
string(19) "2016-04-11 18:59:45" 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 09:30:54" 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 15:56:52" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-22 15:56:52.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.10
string(19) "2016-04-25 18:02:14" 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 23:31:11" 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 07:57:07" 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 03:23:10" 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 11:29:45" 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 09:36:44" 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 19:32:06" 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 06:19:41" 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 14:28:38" 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 09:17:01" 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 12:51:03" 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 14:27:09" 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 20:44:23" 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 04:12:09" 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 10:42:39" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-05-27 10:42:39.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.45
string(19) "2016-01-25 23:39:44" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:44.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.44
string(19) "2016-01-25 23:39:45" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:45.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.42 - 5.4.43
string(19) "2016-01-25 23:39:46" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:46.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.40 - 5.4.41
string(19) "2016-01-25 23:39:47" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:47.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.39
string(19) "2016-01-25 23:39:48" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:48.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.37 - 5.4.38
string(19) "2016-01-25 23:39:49" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:49.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.35 - 5.4.36
string(19) "2016-01-25 23:39:50" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:50.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.32 - 5.4.34
string(19) "2016-01-25 23:39:51" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:51.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.30 - 5.4.31
string(19) "2016-01-25 23:39:52" object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-29 23:39:52.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.29
string(19) "2016-01-25 23:39:52" object(DateTime)#1 (3) { ["date"]=> string(19) "2016-01-29 23:39:52" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.26 - 5.4.28
string(19) "2016-01-25 23:39:53" object(DateTime)#1 (3) { ["date"]=> string(19) "2016-01-29 23:39:53" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.23 - 5.4.25
string(19) "2016-01-25 23:39:54" object(DateTime)#1 (3) { ["date"]=> string(19) "2016-01-29 23:39:54" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.19 - 5.4.22
string(19) "2016-01-25 23:39:55" object(DateTime)#1 (3) { ["date"]=> string(19) "2016-01-29 23:39:55" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.15 - 5.4.18
string(19) "2016-01-25 23:39:56" object(DateTime)#1 (3) { ["date"]=> string(19) "2016-01-29 23:39:56" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.12 - 5.4.14
string(19) "2016-01-25 23:39:57" object(DateTime)#1 (3) { ["date"]=> string(19) "2016-01-29 23:39:57" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.3.22 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/kfSRj on line 4
Process exited with code 255.