php计算两个日期相差多少个月份

PHP 投稿 54400 0 评论

php计算两个日期相差多少个月份

php获取两个日期相差多少个月份

function getMonthDiffNum($startDate, $endDate)
{
    $startDate = strtotime($startDate);
    $endDate = strtotime($endDate);

    $Y = date('Y', $endDate) - date('Y', $startDate);
    $M = date('m', $endDate) - date('m', $startDate);

    return $cha = abs($Y * 12 + $M);
}

$num=getMonthDiffNum('2018-12-11','2019-11-01');
echo $num;

编程笔记 » php计算两个日期相差多少个月份

赞同 (36) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽