php时间
获取2个时间内的所有日期
/**
* 获取2个时间内的所有日期
*
* @access public
* @param string $startDate 开始时间2019-12-30
* @param string $backDate 结束时间2020-01-02
* @return array 返回类型
* array(4) {
* [0]=>
* string(10) "2019-12-30"
* [1]=>
* string(10) "2019-12-31"
* [2]=>
* string(10) "2020-01-01"
* [3]=>
* string(10) "2020-01-02"
* }
*/
if (!function_exists("getBetweenTimeArr")) {
function getBetweenTimeArr(string $startDate, string $backDate): array
{
if (!$startDate || !$backDate) {
return [];
}
$dtStart = strtotime($startDate);
$dtEnd = strtotime($backDate);
$getBetweenTimeArr = [];
while ($dtStart <= $dtEnd) {
$getBetweenTimeArr[] = date('Y-m-d', $dtStart);
$dtStart = strtotime('+1 day', $dtStart);
}
return $getBetweenTimeArr;
}
}
Buy me a cup of coffee 🙂
觉得对你有帮助,就给我打赏吧,谢谢!