我想从 php 中的两个日期中获取总月份数。我在互联网上到处搜索了两个日期之间的闰年计算,但没有找到答案。
如果我的输入是“2019-01-01”到“2019-03-31”,那么我预期的结果是 3 个月,但我得到的结果是 2 个月。
以下是我的代码。
$date1 = strtotime("2019-01-01");
$date2 = strtotime("2019-02-28");
$diff = abs($date2 - $date1);
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24)
/ (30*60*60*24));
printf("%d months",$months);
我哪里错了
慕森王
慕哥6287543