$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