Today now in this post, i will show you How to use where clause with date_format() in Laravel? Here i will share with you about how we can use date_format() aslo with where condition in Laravel query builder. When we are working on our project,some times i need to search with get only selected month and year records from based on created_at(timestamp) column. Here I am thinking to share with you how can we use date_format() of mysql. At last here i will use DB::raw() of Laravel and it’s work fine.
If you have also need to search on this way then you can also do it by this way:
$data = DB::table("items") ->select("id","title","created_at") ->where(DB::raw("(DATE_FORMAT(created_at,'%Y-%m'))"),"2016-07") ->get(); print_r($data);
Thanks for read. I hope it help you. For more you can follow us on facebook.