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

Laravel whereHas and orWhereHas Query Example


laravel whereHas and orWhereHas query example, wherehas and orWhereHas query in laravel, how to use wherehas in laravel

Crop Image Before Upload Using Croppie.js in Laravel 9


Using Laravel 9, crop an image before uploading it using Croppie.js. Before uploading an image, Laravel uses Ajax to crop it with croppie. Cropping an...

Laravel 9 Highcharts Example Tutorial


In this tutorial, I'll give you an example of how to use highchart js to construct a highchart in a laravel 9 application.

Laravel 8/7/6 Google ReCaptcha v2 Form Validation


In form validation, Laravel 8,7,6 uses Google v2 Captcha/Re-Captcha. You will learn how to add Google v2 ReCaptcha form validation to a Laravel form i...

Laravel One to Many Polymorphic Relationship


laravel polymorphic relations example, laravel polymorphic one to many, laravel eloquent polymorphic relations, laravel one to many polymorphic