计算两者相差几个月零几天

网络整理 - 07-27

function diff($date, $date1 = "now")
{
$time = strtotime($date);
$y = date("Y", $time);
$m = date("m", $time);
$d = date("d", $time);

$time1 = strtotime($date1);
$_y = date("Y", $time1);
$_m = date("m", $time1);
$_d = date("d", $time1);

if ($y == $_y)
{
$m1 = $m - $_m;
}
else
{
$m1 = $m + (12 - $_m);
}

if ($d >= $_d)
{
$d1 = $d - $_d;
}
else
{
$m1 --;
$t1 = date("t");
$d1 = $d + ($t1 - $_d);
}

return $m1 . "月零" . $d1 . "天";
}