mysqldateactiverecordwhere-clauselaravel-5.1

Get only records created today in laravel


How do I use the created_at 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.


Solution

  • For Laravel 5.6+ users, you can just do

    $posts = Post::whereDate('created_at', Carbon::today())->get();