2012-01-24 161 views

回答

1
$diff = (int) (abs(strtotime($date1) - strtotime($date2))/(60 * 60 * 24)); 
echo 'diff:' . $diff 
+0

我建議不要使用'strtotime'來代替['DateTime'](http://php.net/DateTime)。 –

1

PHP具有這樣的功能:

http://www.php.net/manual/en/datetime.diff.php

$datetime1 = new DateTime('2009-10-11'); 
$datetime2 = new DateTime('2009-10-13'); 
$interval = $datetime1->diff($datetime2); 
echo $interval->format('%R%a days'); 

輸出

+2 days 
0

你可以把茨艾倫e日期到時間戳:

$ts1 = strtotime("15-02-2012"); 
$ts2 = strtotime("18-03-2012"); 
$diff = ($ts2 - $ts1)/86400; 

echo $diff . " days";