我在Laravel Query Builder中有这样的查询 -
$baseQuery = DB::table( 'project');
//$startDate="2015-09-02" - This format
//$endtDate="2014-08-02" - This format
if(!empty($startDate))
$baseQuery = $baseQuery->where('project.completion_date', '>', $startDate);
if(!empty($endData))
$baseQuery = $baseQuery->where('project.completion_date', '<', $endData);
答案 0 :(得分:1)
试试这个
$startDate = empty($startDate) ? '1970-01-01' : $startDate;
$endDate = empty($endDate) ? '2038-01-01' : $endDate;
DB::table('project')
->whereBetween('completion_date', [$startDate, $endDate])
->get();