3v4l.org

run code in 300+ PHP versions simultaneously
<?php //helper function to pluralize words function pluralize( $count, $text ){ return $count . ( ( $count == 1 ) ? ( " $text" ) : ( " ${text}s" ) ); } /** * Difference of dates * @param type $date1 DateTime first date * @param type $date2 DateTime second date * @return type string year, month, day, hour, minute, second */ function timeDiff($date1, $date2 ){ $string = ""; $interval =$date1->diff($date2); $suffix = ( $interval->invert ? ' ago' : '' ); if ( $v = $interval->y >= 1 ) $string .= pluralize( $interval->y, 'year' ). ', '; if ( $v = $interval->m >= 1 ) $string .= pluralize( $interval->m, 'month' ). ', '; if ( $v = $interval->d >= 1 ) $string .= pluralize( $interval->d, 'day' ). ', '; if ( $v = $interval->h >= 1 ) $string .= pluralize( ($interval->h), 'hour' ) . ', '; if ( $v = $interval->i >= 1 ) $string .= pluralize( $interval->i, 'minute' ). ', '; if ( $v = $interval->i >= 1 ) $string .= pluralize( $interval->s, 'second' ). ' '; return $string . $suffix; } $date1 = new DateTime("2014-05-10 20:00:00"); $date2 = new DateTime("2015-11-20 19:45:00"); //This should produce "1 year, 6 months, 9 days, 23 hours, 45 minutes" //But it does produce "1 year, 6 months, 10 days, 45 minutes" echo timeDiff($date1, $date2); $date3 = new DateTime("2015-11-20 20:00:00"); echo "\n"; //This should, and does produce "1 year, 6 months, 10 days" echo timeDiff($date1, $date3);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /in/Kp26c on line 5 1 year, 6 months, 9 days, 23 hours, 45 minutes, 0 seconds 1 year, 6 months, 10 days,

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:
121.13 ms | 405 KiB | 5 Q