3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 = new DateTime($end_time) -> diff(new DateTime($begin_time)); echo "diff is $diff";
based on vMusC
Output for 5.4.0 - 5.4.34
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /in/pm83g on line 41
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/pm83g on line 41
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/pm83g on line 41
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/pm83g on line 41
Process exited with code 255.