0

I am using laravel 8 and I want to get ids between two dates form created_at column which is timestamp format I use the following code

    $ids=Visit::select('id')->whereBetween('created_at',[$request->input('from_date'),$request->input('to_date')])->get();
return response($ids);

but I get an empty result

I tired to convert the inputs to time using the strtotime() function but also I get the same empty result

    $ids=Visit::select('id')->whereBetween('created_at',[strtotime($request->input('from_date')),strtotime($request->input('to_date'))])->get();
return response($ids);

the input type in view page is date

could you please help with the correct syntax

2
  • what you get in request->input('to_date') Commented May 28, 2021 at 8:39
  • echo $request->input('from_date')." ".$request->input('to_date') print the following 2021-05-20 2021-05-21 Commented May 28, 2021 at 8:42

1 Answer 1

1

You can format using carbon

$fromDate=\Carbon\Carbon::createFromFormat('Y-m-d',$request->input('from_date'));

$toDate=\Carbon\Carbon::createFromFormat('Y-m-d',$request->input('to_date'));

  $ids=Visit::select('id')->whereBetween('created_at',[$fromDate,$toDate])->get();
return response($ids);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.