Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cooperino's avatar

get data by last X number of days back with Query Builder

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

0 likes
2 replies
MichalOravec's avatar
Level 75
Model::whereDate('created_at', '>', now()->subDays(7)->toDateString())->get();
1 like

Please or to participate in this conversation.