2016-12-01 100 views

回答

0

您可以使用此方法來發現兩天天差

$current_date = time(); // or your date as well 
$random_date = strtotime("2010-01-01"); 
$datediff = $current_date - $random_date; 

echo floor($datediff/(60 * 60 * 24)); 

PHP Version > 5低於新的日期/時間函數相加得到差異

$datetime1 = new DateTime("2010-06-20"); 

$datetime2 = new DateTime("2011-06-22"); 

$difference = $datetime1->diff($datetime2); 

echo 'Difference: '.$difference->y.' years, ' 
        .$difference->m.' months, ' 
        .$difference->d.' days'; 

結果會如下:

Difference: 1 years, 0 months, 2 days