3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $x = new DateTimeImmutable('2015-07-31'); $y = $x->modify('first day of previous month'); var_dump($y); $z = $y->setDate($y->format('Y'), $y->format('n')-1,30); var_dump($z);
based on qcmK7
Output for 5.6.19 - 5.6.28, 7.0.4 - 7.2.0
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2015-06-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2015-05-30 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.24 - 5.6.18, 7.0.0 - 7.0.3
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2015-06-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2015-05-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.3.18 - 5.4.45
Fatal error: Class 'DateTimeImmutable' not found in /in/kBJ0a on line 3
Process exited with code 255.