<?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); $diff = $today->diff($mpsAgeT); $years = $diff->y; if (addOne($diff)) { $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"; } function addOne($interval) { $props = ['m', 'd']; foreach ($props as $prop) { if ($interval->{$prop} !== 0) return true; } return false; }
You have javascript disabled. You will not be able to edit any code.