<?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"; }
You have javascript disabled. You will not be able to edit any code.