In this post, we'll go over the where clause in Laravel and show you an example using date format(). We'll go over the where clause in Laravel with an example of date format(). And how to use it, as well as a demonstration if necessary.
In this post, I'll show you how to use Laravel query builder's where condition with date format(). I needed to search for only specified month and year records from the created at(timestamp) column when I was working on my project. I was wondering how I could do it, although I'm familiar with MySQL's date format() function. However, I'm not sure how to use it in a Laravel where clause. Finally, I use Laravel's DB::raw() and it works.
Example:
$data = DB::table("items")
->select("id","title","created_at")
->where(DB::raw("(DATE_FORMAT(created_at,'%Y-%m'))"),"2022-07")
->get();
dd($data);
I hope you will like the content and it will help you to learn Laravel where clause with date_format() example
If you like this content, do share.