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.


Recommended Posts

View All

How to Generate a Variety of QR Codes in a Laravel 9 App


In the Laravel application, a basic QR code generator allows you to generate several sorts of QR Codes.

Laravel 9 Bootstrap 5 Auth Scaffolding


I'll show you how to make a Bootstrap 5 Auth Scaffolding in Laravel 9 in this tutorial. Auth Scaffolding uses the Laravel UI package to create a user...

PayPal Integration in Laravel Example


PayPal Integration in Laravel, laravel paypal integration, laravel setup paypal, laravel paypal integration example

Laravel One to Many Eloquent Relationship


laravel one to many relationship example, laravel one to many sync, one to many relationship laravel 5.6, one to many relationship laravel model

How to Implement Gravatar Image using thomaswelton/laravel-gravatar in Laravel 9


Learn how to easily implement Gravatar image using thomaswelton/laravel-gravatar in Laravel 9. Enhance user profiles with personalized images.