Is there a query, with PHP date or Carbon to get data created x minutes ago?
In my example, I need all data created 3 minutes ago. If the time is 10:00 and data was created, then at when query is made 10:03, I should get all data created at 10:00. If query made 10:04, no data show be returned.
Edit per answer: To return all data created between 3 minutes ago and now.
use App/Foo
use Carbon\Carbon;
[...]
$three_minutes_ago = Carbon::now()->subMinutes(3)->toDateTimeString();
$foo = Foo::where('created_at', '<', $three_minutes_ago)->get(); // Is this correct?
$foo
is always empty no matter data is in Foo
. I've used tinker
to create/save data,
Just tested and this is a working solution:
Foo::whereBetween('created_at', [now()->subMinutes(3), now()])->get()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With