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 git.master, git.master_jit, rfc.property-hooks
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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
51.16 ms | 401 KiB | 8 Q