php获取一个时间段的年、月、日份

$dates = prDates('20180101', '20200101', 'y');
var_dump($dates);
$dates = prDates('20190101', '20200101', 'm');
var_dump($dates);
$dates = prDates('20191101', '20200101', 'd');
var_dump($dates);

//获取一个时间段的年、月、日份
function prDates($start, $end, $type)
{
    $ttype = array(
        'd' => ['Ymd', '+1 days'],
        'm' => ['Ym', '+1 months'],
        'y' => ['Y', '+1 years'],
    );
    $start = strtotime($start);
    $end   = strtotime($end);
    $date_arr = array();

    while ($start < $end) {
        $date_arr[] = date($ttype[$type][0], $start);
        $start      = strtotime($ttype[$type][1], $start);;
    }
    return $date_arr;
}

 

posted @ 2020-06-15 15:51  A-GREATE-USERNAME  阅读(659)  评论(0编辑  收藏  举报