In this tutorial, you will learn how easy it is to get data between two dates from the database using Laravel’s
Let’s say you have an online store with orders data in the table and you want to get all the orders between two dates. In this scenario, where between method is the best fit. So let’s see it in action.
$from = Carbon::now()->subDays(5); $to = Carbon::now(); $orders = Order::whereBetween('created_at', [$from, $to]) ->get(); dd($orders);
$from = Carbon::now()->subDays(5); $to = Carbon::now(); $orders = Order::where('created_at',$from) ->where('created_at',$to) ->get(); dd($orders);