How to use date_format() in where condition using laravel

In this article, i share with you that how to use date_format() with where condition of Laravel query builder.When i was working on my project, i require to search with get only selected month, year and date records from created_at(timestamp) column. I was thinking how can i but i know date format() of mysql. but don’t know how to use in laravel where clause. At last i use DB::raw() of Laravel and its work.

$getdata = DB::table('login_history')
  	->where(DB::raw("(DATE_FORMAT(created_at,'%Y-%m-%d'))"),date('Y-m-d'))
   ->get();

Leave a Reply

Your email address will not be published. Required fields are marked *