whereBetween如何处理此查询

时间:2017-08-20 15:29:17

标签: laravel laravel-query-builder

我想使用whereBetween来处理此查询

select * from schedules where now() BETWEEN start and end

感谢您的关注

2 个答案:

答案 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();