清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
下面就是代码拉: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; // -11if($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.'天';}}
要调用的地方格式
注:数据库内的日期存储字段的格式是datetime函数哦