Reputation: 13
I need to get all data between 08:00 to 12:00 every day
when I used this code
->where('created_at', '>=', \Carbon\Carbon::parse('08:00'))
->where('created_at', '<=', \Carbon\Carbon::parse('12:00'))
it return only current day but I need every day
in php native show this. code but how I can convert it laravel
SELECT *
FROM yourtable
WHERE TIME(created_at) BETWEEN '08:00:00' AND '15:00:00'
Upvotes: 1
Views: 104
Reputation: 603
If created_at
stored as time you may use;
$query->whereBetween('created_at', [\Carbon\Carbon::parse('08:00'), \Carbon\Carbon::parse('12:00'));
More info; https://laravel.com/docs/5.8/queries#where-clauses
if it's stored as datetime you may use;
$query->whereTime('created_at','>=','08:00:00')
->whereTime('created_at','<=','12:00:00')
Upvotes: 1