|
<?
//年月日格式
$str1 = '2011年1月18日';
$str2 = '2010年1月1日';
$pattern='/(\d+)/';
preg_match_all($pattern,$str1,$matches1);
preg_match_all($pattern,$str2,$matches2);
$time1=mktime(0,0,0,$matches1[0][1],$matches1[0][2],$matches1[0][0]);
$time2=mktime(0,0,0,$matches2[0][1],$matches2[0][2],$matches2[0][0]);
$day1 = (int)($time1 - $time2)/(24*3600);
echo '相差天数:'.$day1;
// '-' 分隔格式
$date1 = '2011-1-18';
$date2 = '2010-1-1';
$day2 = (int)(strtotime($date1)-strtotime($date2))/(24*3600);
echo '相差天数:'.$day2;
?>
|
|
|