Laravel查询生成器 - 查询日期不起作用

时间:2015-09-19 02:42:59

标签: mysql laravel laravel-4 laravel-5 query-builder

我在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);

1 个答案:

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