<?php $fecha1 = DateTime::createFromFormat("Y-m-d", '2017-12-05'); $fecha2 = DateTime::createFromFormat("Y-m-d", '2018-02-09'); $diff = $fecha2->diff($fecha1); $diffByType = [ "years" => $diff->format("%y"), "months" => $diff->format("%m"), "days" => $diff->format("%d"), ]; $output = []; foreach ($diffByType as $type => $diff) { if ($diff != 0) { $output[] = $diff." ".$type; } } echo implode(", ", $output);
You have javascript disabled. You will not be able to edit any code.