2010-10-05 25 views
1

我想查找two periods之間的常見days/dates如何在兩個日期範圍中找到常見日期/天數

例如

[period1 - 25/10/2010 - 25-11-2010 ] and [ period2 - 10-11-2010 - 10-12-2010 ] 

這裏15 days26-1010-11是常見的。我如何在PHP或Zend Framework中找到它。

+0

您可以轉換這兩個範圍(即:4日)到UNIX時間戳(使用['的strtotime()'](http://php.net/manual/ en/function.strtotime.php))並找到它們的交集。 – NullUserException 2010-10-05 12:58:50

+0

@NullUserException - 注意夏令時 – 2010-10-05 13:06:39

+0

對不起,我給出的例子是錯誤的......上面例子中的常見日期是11-11到25-11 15天那些在兩個時期。 - Irshad – irshad 2010-10-05 13:42:55

回答

0
$nb_days = (strtotime($period1[1])-strtotime($period2[0]))/86400 

應該工作。

0

使用NullUserException的建議的方法

date_default_timezone_set('GMT'); 


$period1 = array('25-10-2010','25-11-2010'); 
$period2 = array('10-11-2010','10-12-2010'); 

$p1 = range(strtotime($period1[0]),strtotime($period1[1]),86400); 
$p2 = range(strtotime($period2[0]),strtotime($period2[1]),86400); 

$r = array_intersect($p1,$p2); 

foreach($r as $date) { 
echo $date,' - ',date('d-M-Y H:i:s',$date),'<br />'; 
} 
相關問題