3v4l.org

run code in 300+ PHP versions simultaneously
<?php function s_datediff( $str_interval, $dt_menor, $dt_maior, $relative=false){ if( is_string( $dt_menor)) $dt_menor = date_create( $dt_menor); if( is_string( $dt_maior)) $dt_maior = date_create( $dt_maior); $diff = date_diff( $dt_menor, $dt_maior, ! $relative); switch( $str_interval){ case "y": $total = $diff->y + $diff->m / 12 + $diff->d / 365.25; break; case "m": $total= $diff->y * 12 + $diff->m + $diff->d/30 + $diff->h / 24; break; case "d": $total = $diff->y * 365.25 + $diff->m * 30 + $diff->d + $diff->h/24 + $diff->i / 60; break; case "h": $total = ($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h + $diff->i/60; break; case "i": $total = (($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h) * 60 + $diff->i + $diff->s/60; break; case "s": $total = ((($diff->y * 365.25 + $diff->m * 30 + $diff->d) * 24 + $diff->h) * 60 + $diff->i)*60 + $diff->s; break; } if( $diff->invert) return -1 * $total; else return $total; } $begin = mktime(9, 15, 0, date("m") , date("d"), date("Y")); $end = mktime(14, 0, 0, date("m") , date("d"), date("Y")); echo "begin is $begin and end is $end<br>"; $begin_time = date("H:i:s", $begin); $end_time = date("H:i:s", $end); echo "begin_time is $begin_time and end_time is $end_time<br>"; $diff= date_diff(new DateTime($begin_time), new DateTime($end_time)); echo "diff is $diff";
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
begin is 1415348100 and end is 1415365200<br>begin_time is 09:15:00 and end_time is 14:00:00<br> Fatal error: Uncaught Error: Object of class DateInterval could not be converted to string in /in/vMusC:42 Stack trace: #0 {main} thrown in /in/vMusC on line 42
Process exited with code 255.
Output for 8.0.13
begin is 1415351700 and end is 1415368800<br>begin_time is 09:15:00 and end_time is 14:00:00<br> Fatal error: Uncaught Error: Object of class DateInterval could not be converted to string in /in/vMusC:42 Stack trace: #0 {main} thrown in /in/vMusC on line 42
Process exited with code 255.
Output for 7.3.32 - 7.3.33
begin is 1415351700 and end is 1415368800<br>begin_time is 09:15:00 and end_time is 14:00:00<br> Recoverable fatal error: Object of class DateInterval could not be converted to string in /in/vMusC on line 42
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
begin is 1415348100 and end is 1415365200<br>begin_time is 09:15:00 and end_time is 14:00:00<br> Recoverable fatal error: Object of class DateInterval could not be converted to string in /in/vMusC on line 42
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
begin is 1415348100 and end is 1415365200<br>begin_time is 09:15:00 and end_time is 14:00:00<br> Catchable fatal error: Object of class DateInterval could not be converted to string in /in/vMusC on line 42
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
begin is 1415348100 and end is 1415365200<br>begin_time is 09:15:00 and end_time is 14:00:00<br> Fatal error: Call to undefined function date_diff() in /in/vMusC on line 41
Process exited with code 255.
Output for 4.4.5 - 4.4.9
begin is 1415348100 and end is 1415365200<br>begin_time is 09:15:00 and end_time is 14:00:00<br> Fatal error: Call to undefined function: date_diff() in /in/vMusC on line 41
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
begin is 1415348100 and end is 1415365200<br>begin_time is 09:15:00 and end_time is 14:00:00<br> Fatal error: Call to undefined function: date_diff() in /in/vMusC on line 41
Process exited with code 255.
Output for 4.3.0 - 4.3.1
begin is 1415348100 and end is 1415365200<br>begin_time is 09:15:00 and end_time is 14:00:00<br> Fatal error: Call to undefined function: date_diff() in /in/vMusC on line 41

preferences:
342.34 ms | 402 KiB | 459 Q