function diffDate($date1,$date2){ $datestart= date('Y-m-d',strtotime($date1)); if(strtotime($datestart)>strtotime($date2)){ $tmp=$date2; $date2=$datestart; $datestart=$tmp; } list($Y1,$m1,$d1)=explode('-',$datestart); list($Y2,$m2,$d2)=explode('-',$date2); $Y=$Y2-$Y1; // 1 $m=$m2-$m1; // 0 $d=$d2-$d1; // -11 if($d<0){ $d+=(int)date('t',strtotime("-1 month $date2")); $m=$m--; } if($m<0){ $m+=12; $y=$y--; } if($Y == 0 && $m == 0 && $d != 0){ return $d.'天'; }elseif($Y == 0 && $m != 0 && $d != 0){ return $m.'个月'.$d.'天'; }elseif($Y != 0 && $m == 0 && $d != 0){ return $Y.'年'.$d.'天'; }else{ return $Y.'年'.$m.'个月'.$d.'天'; } }