Search code examples
mysqllaravelgettimestampwhere-clause

Laravel get entry from mySql database where timestamp is not older than one day


In laravel project I have mysql table 'users' in which is timestamp column named last_visit. I want to get all users, which last_visit is not older than one day.How to perform that?


Solution

  • You can combine where clauses and Carbon to archive what you want:

    DB::table('users')->where('last_visit', '>', Carbon::today()->subDay(1));
    

    or

    Usee::where('last_visit', '>', Carbon::today()->subDay(1));