3v4l.org

run code in 300+ PHP versions simultaneously
<?php $today = DateTime::createFromFormat('d.m.Y', '17.06.2019'); $dates = [ '17.06.2016', '19.06.2016', '15.06.2016', ]; foreach ($dates as $date) { $mpsAgeT = DateTime::createFromFormat('d.m.Y', $date); // Find year difference $years = $today->format('Y') - $mpsAgeT->format('Y'); // Add to original date (sets it to the same date of the current year) // Only add if the date has passed if ($today > $mpsAgeT->modify('+' . $years . ' years')) { $years++; } /* 17.06.2019 and 17.06.2016 - should returns me 3 17.06.2019 and 19.06.2016 - should returns me 3 17.06.2019 and 15.06.2016 - should returns me 4 */ print $date . " -> " . $years . "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
17.06.2016 -> 3 19.06.2016 -> 3 15.06.2016 -> 4

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