I’m trying to archive month date 1 to month end date with.
below code now get this year month complete date 1 to 31 by below code.
but it only gives current year month I want to pass dynamic year month name or month number to archive date list
$this->dateRange = CarbonPeriod::create(now()->startOfMonth(), now()->endOfMonth())->toArray();
dd($this->dateRange);
Result I get:
01-01-2024
02-01-2024
...
31-01-2024
I’m trying to archive month date 1 to month end date in array.
2
Answers
You can achive that using
->setMonth
:I don’t see why to use
now()
in this case. Create new objects from scratch, and if you want those months on the current year, passnull
as first parameter tocreate()
:And just use
parse()
to work with month name instead of number: