Jan 31
Feb 28
Mar 31
Apr 30
May 15
答案 0 :(得分:3)
我认为你正在寻找这样的东西:
$start = new DateTime('2014-01-01');
$end = new DateTime('2014-05-15');
$tmpStart = $start;
while ( $tmpStart <= $end ) {
$tmpEnd = clone $tmpStart;
$tmpEnd = $tmpEnd->modify('last day of this month');
$tmpEnd = $tmpEnd < $end ? $tmpEnd : clone $end;
echo $tmpStart->format("M") . " " . ($tmpEnd->diff($tmpStart)->format("%a")+1) . "\n";
$tmpStart = $tmpEnd->modify('first day of next month');
}
输出:
Jan 31
Feb 28
Mar 31
Apr 30
May 15
答案 1 :(得分:0)
从cal_days_in_month()函数获取月中的天数,并使用date_diff()比较这些天数
答案 2 :(得分:0)
如果我理解正确,你想找到两个日期之间的天数差异吗?
<?php
$startDate = mktime(0, 0, 0, 1, 1, 1970); //Enter your start date and time
$endDate = mktime(0, 0, 0, 5, 20, 2014); //Enter your end date and time
echo ($endDate-$startDate)/60/60/24; //This works out the number of days between the two
?>
输出:
16210
查看mktime()文档,了解如何在mktime()
函数中输入日期。