Jishad P
Jishad P

Reputation: 703

Laravel 4.2 WhereBetween Not Working

I have a table like below structure, enter image description here

The entry_added_date is storing date equivalent field, (2015-07-27).

Now I want to filer that entries in between two dates with this field.

I tried the below code,

    $start = Input::get('start');
    $end = Input::get('end');

 $arr = DB::table('otc_revenue_entries')
        ->whereBetween('entry_added_date',array($start,$end))
        ->get();
 return Response::json(['data',$arr]);

Where is the wrong in my code, ?

Upvotes: 0

Views: 772

Answers (2)

Jishad
Jishad

Reputation: 2965

Check Below code..

    $startdate = new DateTime($start);
    $start_date = $startdate->format("Y-m-d");
    $enddate = new DateTime($end);
    $end_date = $enddate->format("Y-m-d");

$arr = DB::table('otc_revenue_entries')
        ->leftJoin('otc_users','otc_users.user_id','=','otc_revenue_entries.entry_added_by')
        ->leftJoin('otc_branches','otc_branches.branch_id','=','otc_revenue_entries.entry_branch')
        ->whereBetween('entry_added_date',array($start_date,$end_date))
        ->get();

return Response::json(['data',$arr]);

Upvotes: 2

davsp
davsp

Reputation: 2189

Make sure your $start and $end are actually the same format as your entry_added_date, the comparison might be failing due to that.

Upvotes: 0

Related Questions