function get_month_diff($start, $end = FALSE)
{
$end OR $end = time();
$start = new DateTime("@$start");
$end = new DateTime("@$end");
$diff = $start->diff($end);
return $diff->format('%y') * 12 + $diff->format('%m');
}
{
$end OR $end = time();
$start = new DateTime("@$start");
$end = new DateTime("@$end");
$diff = $start->diff($end);
return $diff->format('%y') * 12 + $diff->format('%m');
}
//echo get_month_diff(strtotime("2017-04-1 6:30:01"), strtotime("2017-08-1 6:30:02")) . "\n";
//echo get_month_diff(strtotime("2017-04-1 00:00:00"), strtotime("2017-08-1 00:00:00")) . "\n";
//echo get_month_diff(strtotime("2018-01-1 00:00:00"), strtotime("2017-12-1 00:00:00")) . "\n";
echo get_month_diff(strtotime("2018-06"), strtotime("2018-04")) . "\n";
来源:https://blog.csdn.net/hyb1234hi/article/details/74066943