For getting the days, try this:
$begintime = '2012-12-19';
$endtime = '2013-02-22';
$bd = new DateTime($begintime);
$ed = new DateTime($endtime);
$c = $bd->format('t') - $bd->format('d') + 1;
$pass = false;
while($bd->format('Y') < $ed->format('Y')
|| $bd->format('n') < $ed->format('n')) {
$bd->modify("+1 month");
echo $c." ";
$c = $bd->format('t');
$pass = true;
}
$c = $ed->format('d');
if(!$pass)
$c -= $bd->format('d') - 1;
echo $c;
See http://ideone.com/07wqkp
$bd->format('t')
gives the maximum number of days in a month.
ideone uses PHP 5.2.11. I suppose with PHP 5.4 you could use
$bd->add(new DateInterval("P1M"));
instead of $bd->modify("+1 month");
.
EDIT: Fixed bug when starting and ending in the same month and year.
EDIT: Reverted to explicit comparisons. On second thought, it's better without the if/else.