$date1 = "2000-01-01";
$date2 = "2011-03-14";
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff/(365 * 60 * 60 * 24));
$months = ceil(($diff - ($years * 365 * 60 * 60 * 24))/((365 * 60 * 60 * 24)/12));
$months2 = floor(($diff - ($years * 365 * 60 * 60 * 24))/((365 * 60 * 60 * 24)/12));
$days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months2 * 30 * 60 * 60 * 24)/ (60 * 60 * 24));
我得到的答案是11 years , 2 months and 14 days
。不应该是11 years, 3 months and 14 days
?计算日期之间的年/月/日
我已经尝试了很多不同的方法,我总是以2个月而不是3个月为目标。有谁知道为什么吗?
为什么会是3个月?不到90天已经过了所以它的<3个月 – JohnP 2011-03-15 08:23:39
你为什么认为应该是3个月?毕竟1和3之间的差异是2 ..如果有的话,应该是2个月和* 13天* ..顺便说一句。日期差异总是很困难,并且取决于“月”的定义。 – poke 2011-03-15 08:24:14
我在你的日期之间只看到两个月:Januar&Februar。你为什么认为应该有三个? – ZeissS 2011-03-15 08:25:03