3v4l.org

run code in 300+ PHP versions simultaneously
<?php $datetime1 = new DateTime('2017-04-26 18:13:06'); $datetime2 = new DateTime('2011-01-17 17:13:00'); // change the millenium to see output difference $diff = $datetime1->diff($datetime2); // this will get you very close, but it will not pad the digits to conform with your expected format echo "Raw Difference: " . $diff->format('%y years %m months %d days %h hours %i minutes %s seconds') . "\n"; // Notice the impact when you change $datetime2's millenium from '1' to '2' echo "Invalid format: " . $diff->format('%Y-%m-%d %H:%i:%s') . "\n"; // only H does it right $details = array_intersect_key((array)$diff,array_flip(['y','m','d','h','i','s'])); echo '$diff = ' . var_export($details, true) . "\n"; printf("Valid format: %04d-%02d-%02d %02d:%02d:%02d", $diff->y, $diff->m, $diff->d, $diff->h, $diff->i, $diff->s); // now all components of datetime are properly padded
Output for git.master, git.master_jit, rfc.property-hooks
Raw Difference: 6 years 3 months 9 days 1 hours 0 minutes 6 seconds Invalid format: 06-3-9 01:0:6 $diff = array ( 'y' => 6, 'm' => 3, 'd' => 9, 'h' => 1, 'i' => 0, 's' => 6, ) Valid format: 0006-03-09 01:00:06

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:
77.09 ms | 406 KiB | 5 Q