3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php date_default_timezone_set('America/Chicago'); var_dump(new \DateTime('-1 month 4:20am')); var_dump((new \DateTime('4:20am'))->sub(new DateInterval('P1M'))); var_dump(new DateTime('last month')); var_dump(new DateTime('2014-02-28 - 1 month')); var_dump(new DateTime('2014-10-30 - 1 month')); var_dump(new DateTime('2014-10-31 - 1 month')); var_dump(new DateTime('2014-11-31 - 1 month'));
Output for 7.2.0
object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 23:10:52.002853" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-01-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-09-30 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-11-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" }
Output for 7.1.10
object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 23:10:52.004091" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-01-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-09-30 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-11-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" }
Output for 7.1.7
object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 23:10:52.005126" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-01-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-09-30 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-11-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" }
Output for 7.1.6
object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 23:10:52.012631" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-01-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-09-30 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-11-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" }
Output for 7.1.5
object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 23:10:52.031405" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-01-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-09-30 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-11-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" }
Output for 7.1.0
object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 23:10:52.004044" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-01-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-09-30 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-11-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" }
Output for 5.5.14 - 7.0.20
object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 04:20:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-05 23:10:52.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-01-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-09-30 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-10-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(26) "2014-11-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" }
Output for 5.5.0 - 5.5.13
object(DateTime)#1 (3) { ["date"]=> string(19) "2016-03-05 04:20:00" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(19) "2016-03-05 04:20:00" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(19) "2016-03-05 23:10:52" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(19) "2014-01-28 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(19) "2014-09-30 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(19) "2014-10-01 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" } object(DateTime)#1 (3) { ["date"]=> string(19) "2014-11-01 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(15) "America/Chicago" }