Kyle Adams Kyle Adams - 9 months ago 110
SQL Question

Get only records created today in laravel

How do I use the

field to get only the records that were created today and no other day or time?

I was thinking of a
->where('created_at', '>=', Carbon::now())
But Im not sure that would work.


You can use whereRaw('date(created_at) = curdate()') if timezone is not a concern or whereRaw('date(created_at) = ?', [Carbon::now()->format('Y-m-d')] ) otherwise.

Since the created_at field is a timestamp, you need to get only the date part of it and ignore the time part.