Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel search for records 7 days old only

i am trying to pull records that are 7 days old only , not older or earlier. But its not working, i'm using Carbon.

->where(DB::raw('date(AppDate)'), Carbon::now()->subDays(7))
like image 206
xTRIFAC70Rx Avatar asked Oct 13 '17 13:10

xTRIFAC70Rx


1 Answers

You can use whereDate for that :

->whereDate('created_at', Carbon::now()->subDays(7))
->get();

In the documentation :

The whereDate method may be used to compare a column's value against a date

PS : Since Laravel 5.3

like image 123
Maraboc Avatar answered Oct 20 '22 22:10

Maraboc