3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tz = new DateTimeZone('Europe/Amsterdam'); $now = new DateTime('2015-10-01', $tz); $then = new DateTime('2015-01-01', $tz); $diff = $now->diff($then); echo sprintf("Expected: %d. Returned: %d\n", 9, $diff->format('%m')); $now = new DateTime('2015-09-01', $tz); $then = new DateTime('2015-01-01', $tz); $diff = $now->diff($then); echo sprintf("Expected: %d. Returned: %d\n", 8, $diff->format('%m')); $now = new DateTime('2015-11-01', $tz); $then = new DateTime('2015-01-01', $tz); $diff = $now->diff($then); echo sprintf("Expected: %d. Returned: %d\n", 10, $diff->format('%m'));

preferences:
55.43 ms | 402 KiB | 5 Q