$aa="2003-02-25";
$bb = date("Y-m-d",time());
function datediffage($before, $after) {
$b = getdate($before);
$a = getdate($after);
$y=$m=0;
if ($a['mon']==1) { //1月,借年
$y=$a['year']-$b['year']-1;$m=$a['mon']-$b['mon']+12;
}
else {
if ($a['mon']>=$b['mon']+1) { //借月后,月相减为正
$y=$a['year']-$b['year'];$m=$a['mon']-$b['mon']-1;
}
else { //借月后,月相减为负,借年
$y=$a['year']-$b['year']-1;$m=$a['mon']-$b['mon']+12-1;
}
}
$datearr = array();
$totalm = "";
if( $y > 0 ){
$totalm = $y*12;//大于1年,转换成月份数
}
$totalm += $m;
for ($i=0; $i < $totalm; $i++) {
array_push($datearr, date("Y-m",mktime(0,0,0,$b['mon']+$i,$d,$b['year'])));
}
return $datearr;
}
print_r(datediffage(strtotime($aa),strtotime($bb)));