Home  >  Q&A  >  body text

Laravel: Filter out users created more than three months ago

<p>In my Laravel application, I want to get all user records where the "created_at" timestamp is three months earlier than the current date. Is this possible using the Eloquent query builder? </p>
P粉115840076P粉115840076389 days ago364

reply all(1)I'll reply

  • P粉146080556

    P粉1460805562023-08-28 14:52:12

    First, you can use Carbon to get the date 3 months ago.

    $date = Carbon::now()->subMonths(3)->format('Y-m-d');

    Then we need all the records before that. So, the query should be -

    $users = User::where('created_at', '<=', $date)->get();

    reply
    0
  • Cancelreply