提问者:小点点

每天两次之间获得查询


我需要每天08:00到12:00之间的所有数据

当我使用这个代码时

->where('created_at', '>=', \Carbon\Carbon::parse('08:00'))

->where('created_at', '<=', \Carbon\Carbon::parse('12:00'))

它只返回今天,但我需要每天

在php原生中显示这个。 代码,但我如何转换它laravel

SELECT *
FROM yourtable
WHERE TIME(created_at) BETWEEN '08:00:00' AND '15:00:00'

共1个答案

匿名用户

如果created_at存储为您可能使用的时间;

$query->whereBetween('created_at', [\Carbon\Carbon::parse('08:00'), \Carbon\Carbon::parse('12:00'));

更多信息; https://laravel.com/docs/5.8/queries#where-clauses

如果它存储为datetime,您可以使用;

 $query->whereTime('created_at','>=','08:00:00')
       ->whereTime('created_at','<=','12:00:00')