How to convert below query into Laravel equivalent query builder
SELECT * FROM `table_name` WHERE '03-05-2017 09:30' BETWEEN `start_date` AND `end_date` AND `who_should`='VV000'
I tried using whereBetween but not working as expected.
$given_time = "03-05-2017 09:30";
\DB::table('table_name')
->whereRaw(" '$given_time' Between start_date and end_date ")
->where("who_should", "=", "VV000")
->get();
$date = new Carbon\Carbon('03-05-2017 09:30');
$date_string=$date->toDateTimeString();
$data_set = DB::table('table_name')
->select(DB::raw('*'))
->where('start_date', '<', $date_string )
->where('end_date', '>', $date_string )
->where('who_should','=','VV000')
->get();
Try above code
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.