2012-04-27 66 views
-1

所有时间我有约会阵列这样希望当前月在PHP

$dateArray = array('2012-04-11','2012-04-29','2012-04-26','2012-04-23','2012-03-21','2012-07-23','2012-12-19','2012-04-27','2012-05-12','2012-05-27','2012-05-28'); 

和IM使用代码来过滤这个数组是

,但它不工作

$start_date= date('Y-m-d',strtotime('first day of this month')) ; 
$end_date =date('Y-m-d',strtotime('first day of next month')) ; 

$month = array(); 

foreach ($dateArray as $dates) 
{ 
$dateTimes = strtotime($dates); 

if (($start_date >= $dateTimes) && ($end_date <= $dateTimes)) 
{ 
    $month[]= $dates; 
} 
} 
var_dump($month); 

但它的不起作用

+0

与magento有什么关系? – Alexandre 2012-04-27 11:28:50

回答

0

你好如果你想显示从阵列具有当月仅日期,然后

foreach($dateArray AS $dateArr){ 

     if(date('M') == date('M' , strtotime($dateArr))){ 
      echo $mnthDate[] = $dateArr;echo "<br/>"; 
     } 
    } 

否则,如果还需要检查这两个年份和月份相同,当前年份和月份。

foreach($dateArray AS $dateArr){ 
     if((date('M') == date('M' , strtotime($dateArr))) && (date('Y') == date('Y' , strtotime($dateArr)))){ 
      $yrDate[] = $dateArr;echo "<br/>"; 
     } 
    } 
1

您需要比较unix时间戳才能正确进行比较:

$dateArray = array('2012-04-11','2012-04-29','2012-04-26','2012-04-23','2012-03-21','2012-07-23','2012-12-19','2012-04-27','2012-05-12','2012-05-27','2012-05-28'); 
$start_date = strtotime('first day of this month') ; 
$end_date = strtotime('first day of next month') ; 

$month = array(); 

foreach ($dateArray as $dates) 
{ 
    $dateTimes = strtotime($dates); 

    if (($start_date >= $dateTimes) && ($end_date <= $dateTimes)) 
    { 
     $month[]= $dates; 
    } 
} 
var_dump($month); 
+0

我已经试过如果((时间() - (26 * 24 * 60 * 60)> = $ dateTimes)&&(时间()+(5 * 24 * 60 * 60)<= $ dateTimes))' – 2012-04-27 11:37:19

+0

还是行不通 – 2012-04-27 11:37:47