如要计算2013-3-09和2013-4-05相差多少天:
<?php
$startdate=strtotime("2013-3-09");
$enddate=strtotime("2013-4-05");
$days=round(($enddate-$startdate)/3600/24) ;
echo $days; //days为得到的天数;
?>
上面的php时间日期函数strtotime已经把字符串日期变成了时间戳,这样只要让两数值相减,然后把秒变成天就可以了,比较的简单。
这是一种方法,另外一种方法
<?php
$date1=date_create("1984-01-28");
$date2=date_create("1980-10-15");
$diff=date_diff($date1,$date2);
echo $diff->format("%R%a days");
?>
但是这个方法有时候会出错,,,不明原因,,,