3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tz = 'Australia/Sydney'; $date_start = new \DateTime('2010-03-01', new \DateTimeZone($tz)); //(+11 UTC) $date_end = new \DateTime('2010-07-29', new \DateTimeZone($tz)); //(+10 UTC) $interval = $date_start->diff($date_end); $utc_start = $date_start->format('U'); $utc_end = $date_end->format('U'); $start = new \DateTime('@' . $utc_start); $start_5_month = new \DateTime($start->format('Y-m-d H:i:s') . ' +5 month', new DateTimeZone($tz)); //5 Month "UTC" without AEST change var_dump('Start: ' . ((new \DateTime('@' . $utc_start))->format('Y-m-d H:i:s')), 'End: with AEST change ' . ((new \DateTime('@' . $utc_end))->format('Y-m-d H:i:s')), $start_5_month, $interval); echo '5 month 2010-07-28 12:00:00.000000 timezone Australia/Sydney/+10 UTC correct';
Output for 8.1.4
string(26) "Start: 2010-02-28 13:00:00" string(41) "End: with AEST change 2010-07-28 14:00:00" object(DateTime)#5 (3) { ["date"]=> string(26) "2010-07-28 13:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Australia/Sydney" } object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(4) ["d"]=> int(28) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(150) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 5 month 2010-07-28 12:00:00.000000 timezone Australia/Sydney/+10 UTC correct
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.12
string(26) "Start: 2010-02-28 13:00:00" string(41) "End: with AEST change 2010-07-28 14:00:00" object(DateTime)#5 (3) { ["date"]=> string(26) "2010-07-28 13:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Australia/Sydney" } object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(5) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(150) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 5 month 2010-07-28 12:00:00.000000 timezone Australia/Sydney/+10 UTC correct

preferences:
82.74 ms | 403 KiB | 77 Q