PHP: 配列内の 2 つの日付間のすべての日付を返す [重複] 質問する

PHP: 配列内の 2 つの日付間のすべての日付を返す [重複] 質問する

予想される入力:

getDatesFromRange( '2010-10-01', '2010-10-05' );

期待される出力:

Array( '2010-10-01', '2010-10-02', '2010-10-03', '2010-10-04', '2010-10-05' )

ベストアンサー1

また、日付期間クラス:

$period = new DatePeriod(
     new DateTime('2010-10-01'),
     new DateInterval('P1D'),
     new DateTime('2010-10-05')
);

これにより、DateTime オブジェクトを含む配列が取得されます。

反復する

foreach ($period as $key => $value) {
    //$value->format('Y-m-d')       
}

おすすめ記事