How to get count of all records created at yesterday

Created at 27-Oct-2021 , By samar

How to get count of all records created at yesterday

Hello everyone, in this post we will look at how to solve "How to get count of all records created at yesterday" in programming.

You can get count of all records created at yesterday. You can get the total number of all records by using the count method after the where condition which helps you to filter the data from table which are created at yesterday
  • Get count of yesterday created records in Laravel

    $count = App\Models\User::whereDate('created_at', '=', \Carbon\Carbon::yesterday()
        ->format('Y-m-d'))->count();
    
    //Demo code with output:
    Route::get('/get-count-of-records', function(){
        $count = App\Models\User::whereDate('created_at', '=', \Carbon\Carbon::yesterday()
        ->format('Y-m-d'))->count();
        return $count;
    });
    

    Output:

    2

    You can simply copy/paste code in routes\web.php and visit URL (/get-count-of-records) to get the output. This code snippet will help you to get the count of all records which are created at yesterday in Laravel. Output may be different as per your database table records. It will return 0 if there is no record exists which is created at yesterday.

     

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.