//时间计算 开始,结束,类型 function shijianjisuan($kaishi,$jieshu,$leixing='shi') { if ($leixing=='shi')//小时 { $sc = floor((strtotime($jieshu) - strtotime($kaishi)) / 3600); } elseif ($leixing=='fen')//分钟 { $sc = floor((strtotime($jieshu) - strtotime($kaishi)) / 60); } elseif ($leixing=='tian')//天 { $sc = floor((strtotime($jieshu) - strtotime($kaishi)) / 3600/24); } return $sc; } $a='2016-08-02'; $b='2016-08-04'; echo shijianjisuan($a,$b,'tian');