Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

VincentMimounPrat99's avatar

How to get last day of a month?

I want to get the last day of a month in laravel. How can I get it?

1 like
8 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@vincentmimounprat99

There are many ways to do that. Since you are using Laravel, you can easily use ->endOfMonth() of Carbon for that.

For example

now()->endOfMonth()

It will return you the last day of the current month.

9 likes
VincentMimounPrat99's avatar

@tisuchi as per instruction my query should work. but it is not working. here is my code

Scholarship::where('expired_at', '>', now()->endOfMonth())
	->orderBy('count', 'desc')
	->get();

And I want to get 10 records only.

7 likes
laracoft's avatar

@vincentmimounprat99 you have to use

Scholarship::whereDate('expired_at', '>', now()->endOfMonth())
    ->orderBy('count', 'desc')
    ->limit(10)
    ->get();
8 likes
tisuchi's avatar

@vincentmimounprat99

To achieve your goal, you need to change your code as follows-

Scholarship::where('expired_at', '>', now()->endOfMonth())
	->orderBy('count', 'desc')
	->take(10)
	->get();
7 likes

Please or to participate in this conversation.