1

I am trying to fetch data from database based on datetime in laravel. But the result returns empty array.When I use the raw query from log file in MYSQL,It displays the results. Thanks In Advance

Below is my laravel query

public function lists(){
$start_date = '20-5-2015';
$end_date = '28-5-2015';
$str_start_date = date("Y-m-d H:i:s",strtotime($start_date));
$str_end_date = date("Y-m-d H:i:s",strtotime($end_date));
$result = DB::table('a')
    ->where('start_date_time','>=',"'$str_start_date'")
    ->where('end_date_time','<=',"'$str_end_date'")
    ->select('a.*')
    ->get();
 dd($result);
}

Below is my raw query for the above laravel query

select `a`.* from `a` where `start_date_time` >= '2015-05-20 00:00:00' and `end_date_time` <= '2015-05-28 00:00:00'

1 Answer 1

2
->where('start_date_time','>=',"'$str_start_date'")
                                ^---------------^

You're embedding extra quotes inside your values...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.