方法一:先用strtotime转换成unix时间戳,然后相减,除以一天的秒数86400.
方法二:先用mktime转换成unix时间戳,然后相减,除以一天的秒数86400.
具体代码如下:
方法一:
class Dtime
{
function get_days($date1, $date2)
{
$time1 = strtotime($date1);
$time2 = strtotime($date2);
return ($time2-$time1)/86400;
}
}
$Dtime = new Dtime;
echo $Dtime->get_days('2007-2-5', '2007-3-6');
?>
方法二:
$temp = explode('-', '2007-2-5');
$time1 = mktime(0, 0, 0, $temp[1], $temp[2], $temp[0]);
$temp = explode('-', '2007-3-6');
$time2 = mktime(0, 0, 0, $temp[1], $temp[2], $temp[0]);
echo ($time2-$time1)/86400;