First date: 07.28.2006
Date now: 07/28/2007
Result: 1 year
')
First date: 07.28.2006
Date now: 01/28/2008
Result: 1 year 6 months
First date: 07.28.2006
Date now: 07/28/2008
Result: 2 years
First date: 07.28.2006
Date now: 08/30/2008
Result: 2 years 1 month 2 days
function pf($n, $form1, $form2, $form5) {
$n = abs($n) % 100;
$n1 = $n % 10;
if ($n > 10 && $n < 20) return $form5;
if ($n1 > 1 && $n1 < 5) return $form2;
if ($n1 == 1) return $form1;
return $form5;
}
$mktime = mktime(0,0,0,7,28,2006);
$nowTime = mktime(0,0,0,7,28,2007); //time();
// CheckGregorian
$y = date("Y",$nowTime);
$minus = 0;
if(!checkdate(2,29,$y)) $minus = 86400;
$mSec = $nowTime - $mktime - $minus;
$yDay = 365 * 86400;
$year = ($mSec - ($mSec % $yDay)) / $yDay; //31557600
$mSec = $mSec - ($year * $yDay);
$month = ($mSec - ($mSec % 2629800)) / 2629800;
$mSec = $mSec - ($month * 2629800);
$day = ($mSec - ($mSec % 86400)) / 86400;
if($year != 0) echo " $year ".pf($year,"","","");
if($month != 0) echo " $month ".pf($month,"","","");
if($day != 0) echo " $day ".pf($day,"","","");
Source: https://habr.com/ru/post/17572/
All Articles