Hey guys I've been trying to get an array with the past 30 days in laravel. Trying to use Carbon to get the days now and want to get count it back 30 days any idea how i can get that done? Example 19,18,17,16,15,14 etc.
Asked
Active
Viewed 2,216 times
2 Answers
0
Not sure what exactly you want, but I believe this is what you are looking for....
$now = \Carbon\Carbon::now();
$dates = [$now->format('M d, Y')];
for($i = 1; $i < 30; $i++) {
$dates[] = $now->subDays($i)->format('M d, Y');
}
print_r($dates);
Let me know if this solves your answer.

prateekkathal
- 3,482
- 1
- 20
- 40
0
This question was earlier asked here link to question
I copied the code from the other answer for reference:
$period = CarbonPeriod::create('2018-06-14', '2018-06-20');
// Iterate over the period
foreach ($period as $date) {
echo $date->format('Y-m-d');
}
// Convert the period to an array of dates
$dates = $period->toArray();

dingezzz
- 56
- 8