php计算两个日期相差的月份

使用函数式方法来创建时间,月份计算差值。

$startStr = '2021-10-01 00:00:00';
$endStr = '2022-01-06 18:00:00';
$start = date_create($startStr);
$end =  date_create($endStr);
$diff = $start->diff($end);
$diffMonth = intval($diff->format('%y')) * 12 + intval($diff->format('%m'));
echo $diffMonth;

引自:https://www.cnblogs.com/zwtqf/p/10063949.html

Author: thinkwei

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注