3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set("UTC"); $dt1 = new DateTime("2012-06-25"); $dt2 = new DateTime("2012-07-27"); $dt3 = new DateTime("2012-07-02"); $iv = $dt1->diff($dt2); var_dump($iv); $dt4 = $dt3->add($iv); echo $dt4->format("c");
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.26, 8.0.0 - 8.0.13, 8.1rc1 - rc3
object(DateInterval)#4 (16) { ["y"]=> int(0) ["m"]=> int(1) ["d"]=> int(2) ["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(32) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } 2012-08-04T00:00:00+00:00

preferences:
36.24 ms | 461 KiB | 5 Q