Kyle Adams Kyle Adams - 2 years ago 186
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download