3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dateTimeBeforeStr = "2024-09-01 00:00:00"; $dateTimeBefore = new DateTimeImmutable($dateTimeBeforeStr); $dateTimeAfter = $dateTimeBefore->modify("-1 second"); $dateTimeAfterStr = $dateTimeAfter->format('Y-m-d H:i:s'); var_dump($dateTimeBeforeStr); var_dump($dateTimeBefore); var_dump($dateTimeAfter); var_dump($dateTimeAfterStr);
Output for 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
string(19) "2024-09-01 00:00:00" object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2024-09-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2024-08-31 23:59:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(19) "2024-08-31 23:59:59"

preferences:
43.5 ms | 407 KiB | 5 Q