Maybe this
Time::whereRaw("DAY(created_at) = '" . Carbon::yesterday()->format('Y-m-d') . "'")->get()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
How can I query yesterday's record only?.
This is what I have done so far, but not working.
'''
$countYesterday = Timer::where('created_at','=', Carbon::yesterday())->get();
'''
Plus, How about this week and This month as well.
Thank's :)
Is appearing any error?
This should give all records which have date equal to yesterday
$yesterday = date("Y-m-d", strtotime( '-1 days' ) );
$countYesterday = Timer::whereDate('created_at', $yesterday )->get();
Also take a look at documentation for whereDate, whereMonth, whereYear https://laravel.com/docs/5.3/queries#where-clauses
Please or to participate in this conversation.