3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $monday = new DateTime('this week monday'); $sunday = new DateTime('this week sunday'); $monday->setTime(0, 0, 0); $sunday->setTime(23, 59, 59); $nextMonday = clone $monday; $nextMonday->modify('+1 week'); $nextSunday = clone $sunday; $nextSunday->modify('+1 week'); var_dump( array('monday' => $monday->format('Y-m-d H:i:s'), 'sunday' => $sunday->format('Y-m-d H:i:s'), 'monday' => $nextMonday->format('Y-m-d H:i:s'), 'sunday' => $nextSunday->format('Y-m-d H:i:s')) );
based on TXnon
Output for 5.4.8 - 5.4.45, 5.6.28, 7.0.20 - 7.2.0
array(2) { ["monday"]=> string(19) "2015-09-21 00:00:00" ["sunday"]=> string(19) "2015-09-27 23:59:59" }
Output for 5.6.21, 7.0.6
array(2) { ["monday"]=> string(19) "2016-05-09 00:00:00" ["sunday"]=> string(19) "2016-05-15 23:59:59" }
Output for 5.5.30, 5.6.14 - 5.6.16, 7.0.5
array(2) { ["monday"]=> string(19) "2016-04-04 00:00:00" ["sunday"]=> string(19) "2016-04-10 23:59:59" }
Output for 5.5.33, 5.6.19, 7.0.4
array(2) { ["monday"]=> string(19) "2016-03-14 00:00:00" ["sunday"]=> string(19) "2016-03-20 23:59:59" }
Output for 5.5.32, 5.6.17 - 5.6.18, 7.0.3
array(2) { ["monday"]=> string(19) "2016-03-21 00:00:00" ["sunday"]=> string(19) "2016-03-27 23:59:59" }
Output for 5.5.31, 7.0.0 - 7.0.2
array(2) { ["monday"]=> string(19) "2016-03-28 00:00:00" ["sunday"]=> string(19) "2016-04-03 23:59:59" }
Output for 5.6.20
array(2) { ["monday"]=> string(19) "2016-04-11 00:00:00" ["sunday"]=> string(19) "2016-04-17 23:59:59" }
Output for 5.5.29, 5.5.34, 5.6.13
array(2) { ["monday"]=> string(19) "2016-04-18 00:00:00" ["sunday"]=> string(19) "2016-04-24 23:59:59" }
Output for 5.5.27 - 5.5.28, 5.6.11 - 5.6.12
array(2) { ["monday"]=> string(19) "2016-04-25 00:00:00" ["sunday"]=> string(19) "2016-05-01 23:59:59" }
Output for 5.5.25 - 5.5.26, 5.6.8 - 5.6.10
array(2) { ["monday"]=> string(19) "2016-05-02 00:00:00" ["sunday"]=> string(19) "2016-05-08 23:59:59" }
Output for 5.5.24, 5.5.35 - 5.6.7
array(2) { ["monday"]=> string(19) "2016-05-30 00:00:00" ["sunday"]=> string(19) "2016-06-05 23:59:59" }
Output for 5.4.2 - 5.4.7
array(2) { ["monday"]=> string(19) "2015-11-02 00:00:00" ["sunday"]=> string(19) "2015-11-08 23:59:59" }
Output for 5.3.18 - 5.3.29
array(2) { ["monday"]=> string(19) "2015-09-28 00:00:00" ["sunday"]=> string(19) "2015-10-04 23:59:59" }