2016-11-18 49 views
0

两个日期之间得到所有我得到两个日期从用户,例如:如何通过碳

2016-10-01 
2016-11-05 

现在我想获得这两个日期之间的所有日期:

2016-10-01 
2016-10-02 
2016-10-03 
2016-10-04 
... 
2016-11-05 

我想我必须使用carbon库。但我不知道该怎么办!

+0

的http:// carbon.nesbot.com/docs/ - 查看addDay函数并使用while循环。 – ceejayoz

+0

可能有帮助:http://stackoverflow.com/questions/31849334/php-carbon-get-all-dates-between-date-range – castis

回答

1

试试这个:

$from = Carbon::parse('2016-10-01'); 
$to = Carbon::parse('2016-11-05'); 

随着Carbon

$dates = []; 

for($d = $from; $d->lte($to); $d->addDay()) { 
    $dates[] = $d->format('Y-m-d'); 
} 

return $dates; 
-2

我学习laravel(本人菜鸟),我在这个页面中看到http://carbon.nesbot.com/docs/也许可以帮助你

+1

欢迎来到Stack Overflow。当你得到片刻时,请查看[如何回答](http://stackoverflow.com/help/how-to-answer)。 – castis