Level 75
Model::whereDate('created_at', '>', now()->subDays(7)->toDateString())->get();
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Is it possible to use query builder to get all rows going back in specified number of days?
For example get all rows of the last 7 days, or last 30 days... etc
Edit: I'm not sure this is correct:
->whereDate('created_at', Carbon::now()->subDays(7))
because it's only equal to
Model::whereDate('created_at', '>', now()->subDays(7)->toDateString())->get();
Please or to participate in this conversation.