tisuchi
December 2017
M T W T F S S
« Nov    
 123
45678910
11121314151617
18192021222324
25262728293031

Categories


How to use Laravel whereBetween properly?

tisuchitisuchi

I realized that using whereBetween is not that easy. Personally I have faced problem to use that. Here is the final thought that I can come out-

$month = 01;
$year = 2018;

return User::whereBetween('created_at', [$year . "-" . $month . "-01 00:00:00", $year . 
"-" . $month . "-" . cal_days_in_month(CAL_GREGORIAN, $month, $year) . " 23:59:59"])
                ->get();

Here I used a php function called cal_days_in_month() so that you can use any year and month that you want.

 

Enjoy.

<p>I speak PHP, Laravel, MySql, JavaScript, VueJS, Python, Bengali and English. I am originated from Bangladesh, currently working in Malaysia. My day time job is to develop web apps for EDV Standard, and night time, I solve coding issues for communities.</p>

Comments 0
There are currently no comments.