try this
for start of the month
\Carbon\Carbon::now()->subMonth(1)->startOfMonth();
and for end of the month
\Carbon\Carbon::now()->subMonth(1)->endOfMonth();
Hope that will help .
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
What I want to achieve here is to start from the begging of the previous month, exactly at the begging of it ( on day one 12AM )
this does not provide the expected results
\Carbon\Carbon::now()->startOfMonth()->subMonths(1)->format('Y-m-d');
This instead works
\Carbon\Carbon::now()->startOfMonth()->subMonths(1)->subDays(1)->format('Y-m-d');
where these date gets passed to the query below
$list = $this->todo->between($start, $end)->get();
and here is the scopeBetween
public function scopeBetween($query, $from, $to) {
$from = Carbon::createFromFormat('Y-m-d', $from)->format('Y-m-d G:i:s');
$to = Carbon::createFromFormat('Y-m-d', $to)->format('Y-m-d G:i:s');
$query->whereDate('date_of_transaction', '>=', $from);
$query->whereDate('date_of_transaction', '<=', $to);
}
P.S
In my DB schema, I have field date_of_transaction as Date data type which is stored in this format '2015-09-01'
Please or to participate in this conversation.