-1

私はこのような日付配列を持っています

$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= 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);

しかし、それは機能していません

4

2 に答える 2

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);
于 2012-04-27T11:28:00.863 に答える
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/>";
        }
    }
于 2012-04-27T11:37:07.417 に答える