1

i want to take input date as a parameter and search between the dates that are given in input.

Theses are the timestamps() provided by laravel to create the two fields as created_at and upated_at.I want to search between these dates that are given in created_at and updated_at but unable to find the data between these dates. Following is the code that i have create

` $startDate = $request->input('created_at');
  $endDate   = $request->input('updated_at');

->select()
->whereBetween('created_at','updated_at',[$startDate,$endDate])
->get();`
ahmad izhar
  • 150
  • 1
  • 13

2 Answers2

1

I think whereBetween only accepts 2 parameters. The first being the column name and the second the array with values to test. Check: https://laravel.com/docs/5.5/queries#where-clauses

You would want something like:

->whereBetween('created_at', [$startDate,$endDate])
->whereBetween('updated_at', [$startDate,$endDate])
Hedegare
  • 2,037
  • 1
  • 18
  • 22
  • bro, it gives me null then as it has values between the dates given.. anyhow thanks for you response. i will recheck my code :) and let you know if it works – ahmad izhar Sep 08 '17 at 10:58
  • @ahmadizhar Could you perhaps should us the whole function? – Hedegare Sep 08 '17 at 10:59
1

The error:

Argument 2 passed to Illuminate\Database\Query\Builder::whereBetween() must be of the type array

is because the second parameter of whereBetween() is an array, and you pass a string 'updated_at' here. So change it to like:

->whereBetween('created_at', [$startDate,$endDate])
->whereBetween('updated_at', [$startDate,$endDate])

Reference

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59