Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show list of registered users base on current month using laravel

Tags:

laravel

Im new to laravel and im tryin to learn the fundamentals of it. My question is how can I display all the registered users that is registered only on the current month.

like image 229
Mr.Despicable Avatar asked Dec 30 '25 16:12

Mr.Despicable


2 Answers

$from = now()->startOfMonth(); // first date of the current month
$to = now();
$usersRegisteredThisMonth = User::whereBetween('created_at', [$from, $to])->get();
like image 159
Mahmudul Hasan Avatar answered Jan 01 '26 13:01

Mahmudul Hasan


There is a simple way of doing it.

Just use this code

User::whereMonth('created_at', now()->month) // checking if the month of created_at is current month
->whereYear('created_at', now()->year) // checking if the year of created_at is current year
->get();

This line will give you Users from current month.

like image 38
Akhzar Javed Avatar answered Jan 01 '26 14:01

Akhzar Javed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!