Maybe instead of 08 you try 20 because you are using 24 hours format. So it cannot be before 8AM and after 2PM that does not make sense.
May 3, 2022
9
Level 4
Query whereBetween with date and time
I want to query the data where created between this time 02:00:00 to 08:00:00, I tried below but don't get the data while i have some records created between that time,
Kindly where i did wrong
$start=Carbon::now()->format('Y-m-d')." 14:52:23";
$start1=Carbon::now()->format('Y-m-d')." 08:59:59";
// $tomorrow = Carbon::tomorrow()->format('Y-m-d');
// ->whereDate('created_at', '>=', $startDate)
// ->whereDate('created_at', '<=', $endDate)
$data1=DB::table('requisitions')
->whereTime('created_at','>=',$start )
->whereTime('created_at','<=',$start1 )
->get();
// =Requisition::whereBetween('created_at', [$start, $end." 08:59:59"])->get();
dd($data1);
Level 104
@melx that's a different query:
$start = today()->setTime(8, 0);
$end = today()->setTime(16, 0);
$data1 = DB::table('requisitions')
->whereBetween('created_at', [$start, $end])
->get();
Please or to participate in this conversation.