3v4l.org

run code in 300+ PHP versions simultaneously
<?php $inizio = new DateTime('2022-03-21 23:00.000001 Europe/Rome'); $fine = new DateTime('2022-03-22 05:05.000002 Europe/Rome'); $differenza = date_diff($fine,$inizio); $output = $differenza->i; var_dump($output); $string = $output . ''; if(strlen($output . '') == 1) $string = '0' . $output; var_dump($string, 'Stampa su schermo il mio oggetto DateInterval contenuto in $differenza: ', $differenza, $differenza->format('%R%a days')); //Formato con riempimento 0 var_dump($differenza->format('%I'));
Output for 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
int(5) string(2) "05" string(72) "Stampa su schermo il mio oggetto DateInterval contenuto in $differenza: " object(DateInterval)#3 (10) { ["y"]=> int(1) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(6) ["i"]=> int(5) ["s"]=> int(0) ["f"]=> float(0) ["invert"]=> int(1) ["days"]=> int(365) ["from_string"]=> bool(false) } string(9) "-365 days" string(2) "05"
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.30
int(5) string(2) "05" string(72) "Stampa su schermo il mio oggetto DateInterval contenuto in $differenza: " object(DateInterval)#3 (16) { ["y"]=> int(1) ["m"]=> int(0) ["d"]=> int(0) ["h"]=> int(6) ["i"]=> int(5) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=> int(365) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } string(9) "-365 days" string(2) "05"

preferences:
78.65 ms | 409 KiB | 5 Q