3v4l.org

run code in 300+ PHP versions simultaneously
<?php $startLM = new DateTime('first day of previous month', new DateTimeZone('America/Detroit')); $startLM->modify('today'); $startLM->setTimezone(new DateTimeZone('UTC')); $startLastMonth = $startLM->format('Y-m-d H:i:s'); $endLM = clone $startLM; $endLM->modify('+1 month'); $endLM->modify('+1 day'); $endLastMonth = $endLM->format('Y-m-d H:i:s'); var_dump($startLastMonth); echo ' '; var_dump($endLastMonth);
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
string(19) "2015-07-01 04:00:00" string(19) "2015-08-02 04:00:00"
Output for 5.3.6 - 5.3.29
string(19) "2015-10-01 04:00:00" string(19) "2015-11-02 04:00:00"
Output for 5.3.5
string(19) "2015-10-01 05:51:26" string(19) "2015-11-02 05:51:26"
Output for 5.3.2 - 5.3.4
string(19) "2015-10-01 05:51:27" string(19) "2015-11-02 05:51:27"
Output for 5.3.0 - 5.3.1
string(19) "2015-10-01 05:51:28" string(19) "2015-11-02 05:51:28"
Output for 5.2.0 - 5.2.17
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (first day of previous month) at position 10 (o): The timezone could not be found in the database' in /in/QtGnf:3 Stack trace: #0 /in/QtGnf(3): DateTime->__construct('first day of pr...', Object(DateTimeZone)) #1 {main} thrown in /in/QtGnf on line 3
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/QtGnf on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_VARIABLE in /in/QtGnf on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_VARIABLE in /in/QtGnf on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/QtGnf on line 9
Process exited with code 255.

preferences:
304.52 ms | 401 KiB | 459 Q