3v4l.org

run code in 200+ php & hhvm versions
<?php $d1 = new DateTime('2019-06-12 15:32:15'); $d2 = new DateTime('2019-06-05'); var_dump($d2->diff($d1)->format("%a")); $d1 = new DateTime('2019-06-12 15:32:15'); $d2 = new DateTime('2019-06-05 15:32:12'); var_dump($d2->diff($d1)->format("%a")); $d1 = new DateTime('2019-06-12'); $d2 = new DateTime('2019-06-05 15:32:12'); var_dump($d2->diff($d1)->format("%a")); $d1 = new DateTime('2019-06-12 00:00:00'); $d2 = new DateTime('2019-06-05 00:00:00'); var_dump($d2->diff($d1)->format("%a")); /* $datePeriod = new DatePeriod($d2,new DateInterval("P1D"), $d1); //var_dump($datePeriod); foreach($datePeriod as $dt) { var_dump($dt->format('Y-m-d')); } */
based on laEnU
Output for 7.1.25 - 7.3.6
string(1) "7" string(1) "7" string(1) "6" string(1) "7"