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

BrainyT's avatar

Get users five days to expires date

I have a table with users and expires_date table, how do I write an Eloquent query to filter from the database and only pick users who have five(5) days more to the expiration date, by comparing the current date and expires date?

0 likes
4 replies
MohamedTammam's avatar
$fiveDaysAgoDate = now()->addDays(-5);
$users = User::whereDate('expire_date', '=', $fiveDaysAgoDate->format('Y-m-d'))->get()
1 like
Snapey's avatar
Snapey
Best Answer
Level 122

    $users = User::whereDate('expire_date', now()->addDays(5))->get();

Please or to participate in this conversation.