Eloquent date filtering: whereDate() , where and other method

If we want to filter entires created date. we have a timestamp field created_at, updated_at. here we have filter the DATE only from the timestamp.

$q->where(DB::raw("DATE(created_at) = '".date('Y-m-d')."'"));

We can also use Carbon:

$q->whereDate('created_at', '=', Carbon::parse('2018-02-06')->toDateString());
Leave a Comment