How To Get Data With Date Format Between Year and Month in Laravel

0
38

Hello Laravel lover’s, now in this post tutorial we will implement how to get data from database MySQL where date between year and month. So, this tutorial will give u simple and easy way to get data from MySQL database where date between year and month.

With Laravel you will learn where get data from date format between year and month, this query will use whereRaw(“DATE_FORMAT(created_at, ‘%Y’) = Year”) and whereRaw(“DATE_FORMAT(created_at, ‘%m’) = month”).

So in this tutorial i will give you simple example getting data from database MySQL using date format between year and month. so let’s see following solution and we hope this can help you.

To get data using date format in laravel between year and month the solution will be like this.

$query = DB::table('users')
                ->whereRaw("DATE_FORMAT(created_at, '%Y') = 2021")
                ->whereRaw("DATE_FORMAT(created_at, '%m') = 1")
                ->orderBy('id_users','ASC')
                ->get();

So, i hope this short and simple tutorial will help you.

LEAVE A REPLY

Please enter your comment!
Please enter your name here