我想使用whereBetween来处理此查询
select * from schedules where now() BETWEEN start and end
感谢您的关注
答案 0 :(得分:0)
您可以将此查询编写为:
$schedules = DB::table('schedules ')->select( 'id','name')
->where( DB::raw('now()'), '>=', 'startDateField' )
->where( DB::raw('now()'), '<=', 'endDateField' )
->get();
同样根据@Devon的评论,您可以使用whereBetween
:
$schedules = DB::table('schedules ')->select( 'id','name')
->whereBetween( DB::raw('now()'), array('startDateField', 'endDateField')
->get();
答案 1 :(得分:0)
你可以这样做
$schedules = DB::table('schedule')->select('id', 'name')
->whereBetween( DB::raw('now()'), [$startDate, $endDate])
->get();