Emma Mfinanga
Emma Mfinanga

Reputation: 51

how to find data in previous date range in laravel

hellow I want to get the logic to find the previous data in date range

Example we fetch data from 2020-04-01 to 2020-05-02, so want to get the data from previous this range

anyone can help the logic from here

this query is just return the data of date range, but not previous

       public function stock_by_period(Request $request){
                   $from = date('Y-m-d', strtotime($request->from);
                  $to = date('Y-m-d', strtotime($request->to)

                 $data=Loading::whereBetween('reservation_from', [$from, $to])->get();

                   dd($data);
             }

anyone can help me on this

Upvotes: 0

Views: 140

Answers (1)

Omer YILMAZ
Omer YILMAZ

Reputation: 1263

 public function stock_by_period(Request $request){
      $from = date('Y-m-d', strtotime("-1 day", strtotime($request->from));
      $to = date('Y-m-d', strtotime($request->to)

      $data=Loading::whereBetween('reservation_from', [$from, $to])->get();
      dd($data);
 }

Upvotes: 1

Related Questions