📜  php 计算两个日期之间的月数 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:52.835000             🧑  作者: Mango

代码示例1
$date1 = '2000-01-25';
$date2 = '2010-02-20';

$ts1 = strtotime($date1);
$ts2 = strtotime($date2);

$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);

$month1 = date('m', $ts1);
$month2 = date('m', $ts2);

$diff = (($year2 - $year1) * 12) + ($month2 - $month1);