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))
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))
I have a solution, but its not using Carbon.
->whereRaw('DATE(AppDate) = DATE_SUB(CURDATE(), INTERVAL 7 DAY)')
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
I have a solution, but its not using Carbon.
->whereRaw('DATE(AppDate) = DATE_SUB(CURDATE(), INTERVAL 7 DAY)')
To sum my last 7 days of records:
$date = \Carbon\Carbon::today()->subDays(7);
$Profitinsevendays = DB::table('n_profit_loss')->where('datetime', '>=', $date)->sum('profit_or_loss');
© 2022 - 2024 — McMap. All rights reserved.