谢谢!
无论从几号开始,都算一个月,按自然月算,不是满三十天才算一个月,比如说:2012-12-31到2013-05-22,12月,1月,2月,3月,4月,5月,一共是6个月,php怎么计算?
追答$date1='2012-12-31';
$date='2013-05-22';
echo ctime($date1, $date);
function ctime($date1, $date)
{
$time = strtotime($date);
$y = date("Y", $time);
$m = date("m", $time);
$d = date("d", $time);
$time1 = strtotime($date1);
$_y = date("Y", $time1);
$_m = date("m", $time1);
$_d = date("d", $time1);
if ($y == $_y)
{
$m1 = $m - $_m;
}
else
{
$m1 = $m + (12 - $_m);
}
if ($d >= $_d)
{
$d1 = $d - $_d;
}
else
{
$m1 --;
$t1 = date("t");
$d1 = $d + ($t1 - $_d);
}
if($d1>0){
return $m1+1;
}else{
return $m1;
}
}