YouTube Icon

Code Playground.

How to use date_format() in where condition using laravel

CFG

How to use date_format() in where condition using laravel

In this post, I share with you how to use ddate_format() with the condition of the Laravel query builder. When I was working on my project, I need to search from the created at(timestamp) column with only the selected month, year and date records. I thought how can I do it, but I know mysql's date format). (But don't know where to use the clause in laravel. Finally I use Laravel's DB::raw() and its work.
 

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




CFG