Date function to display all dates between two dates

前端 未结 3 1878
粉色の甜心
粉色の甜心 2020-12-06 11:39

Is there any PHP function to display all dates between two dates?

3条回答
  •  囚心锁ツ
    2020-12-06 12:22

    There is the DatePeriod class.

    EXAMPLE:

    $begin = new DateTime('2013-02-01');
    $end = new DateTime('2013-02-13');
    
    $daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);
    
    foreach($daterange as $date){
        echo $date->format("Y-m-d") . "
    "; }

    (P1D stands for period of one day, see DateInterval for further documentation)

提交回复
热议问题