3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php if (class_exists('DateTime')) { $date = new DateTime('2013-10-31'); $date->modify('-1 month'); printf("2013-10-31, -1 month: %s\n", $date->format('m')); $date = new DateTime('2013-10-31'); $date->modify('first day of 1 month ago'); printf("2013-10-31, first day of 1 month ago: %s\n", $date->format('m')); } else { print 'Not supported.'; }
Output for 5.2.0 - 5.2.12, 5.5.0 - 7.1.0
2013-10-31, -1 month: 10 2013-10-31, first day of 1 month ago: 09
Output for 5.4.0 - 5.4.45
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.' in /in/ChWhO:4 Stack trace: #0 /in/ChWhO(4): DateTime->__construct('2013-10-31') #1 {main} thrown in /in/ChWhO on line 4
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead' in /in/ChWhO:4 Stack trace: #0 /in/ChWhO(4): DateTime->__construct('2013-10-31') #1 {main} thrown in /in/ChWhO on line 4
Process exited with code 255.
Output for 5.2.13 - 5.2.17
2013-10-31, -1 month: 10 Warning: DateTime::modify(): Failed to parse time string (first day of 1 month ago) at position 10 (o): The timezone could not be found in the database in /in/ChWhO on line 8 2013-10-31, first day of 1 month ago: 10
Output for 4.3.0 - 5.1.6
Not supported.