S M Abrar Jahin
S M Abrar Jahin

Reputation: 14578

Laravel Query Builder - Query on Date Not Working

I have a query like this in 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);

Upvotes: 0

Views: 355

Answers (1)

M0rtiis
M0rtiis

Reputation: 3774

try this

$startDate = empty($startDate) ? '1970-01-01' : $startDate;
$endDate = empty($endDate) ? '2038-01-01' : $endDate;

DB::table('project')
    ->whereBetween('completion_date', [$startDate, $endDate])
    ->get();

Upvotes: 1

Related Questions