Laravel Eloquent get Date from DateTime $request->from = somedate;
$request->to = somedate;
$xyz = Reports::with('doctors')->whereDate('created_at',[$request->from,$request->to])->get();
How do i fetch records which lie between from and to date, where created is in dateTime format.
DB::table('doctors')->whereBetween('created_at', [$request->from, $request->to])->get();
// or
Reports::with('doctors')->whereBetween('created_at', [$request->from, $request->to])->get();
Is this working?
Eloquent has a whereBetween api method.
https://laravel.com/docs/5.6/queries#where-clauses
Reports::with('doctors')->whereBetween('created_at',[$request->from,$request->to])->get();
When your request date format is not in the correct format, then you can use Carbon to parse it in the right format.
$dt = Carbon::parse($request->to);
$dt->toDateTimeString();
No..none of this is working.
$report_info = Reports::with('masters')->whereDate('created_at','>=',$request->from)->orWhereDate('created_at','<=',$request->to)->get();
Take care with your chaining:
when you append orWhereDate than only this condition must be true.
For your between check you must chain two whereDate conditions.
Reports::with('masters')->whereDate('created_at','>=',$request->from)->whereDate('created_at','<=',$request->to)->get();
Can you post your request()->to input format
Yes. This works. Thanx
$start = Carbon::parse($request->from)->format('Y-m-d');
$end = Carbon::parse($request->to)->format('Y-m-d');
$report = Reports::with('booking')->whereDate('created_at','>=',$start)->WhereDate('created_at','<=',$end)->get();
created_at date format was different so had to parse it initially.
If i want to get only date from created_at column. Then how to write query for this purpose?
@hamzakhan17826 how is this question related to your problem?
Start a new question please
Please sign in or create an account to participate in this conversation.