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

Fajar's avatar
Level 2

Carbon addDays

hello how to place a day to add carbon

This is the code that I wrote

Carbon::now()->lastOfMonth()->toDateString();

I want to add the code above to 37 days Thanks for your help

0 likes
9 replies
ftiersch's avatar
->addDays(37)

But it depends where you add them to.

Carbon::now()->addDays(37)->lastOfMonth()->toDateString();

This would give you the last day of the month we are in in 37 days.

Carbon::now()->lastOfMonth()->addDays(37)->toDateString();

This would give you 37 days after the end of the current month.

Fajar's avatar
Level 2

if i try this

Carbon::now()
                                            ->lastOfMonth()
                                            ->addDays(7)
                                            ->toDateString();

i get this

"2019-10-07"
ftiersch's avatar

Yes... Sorry but I have no idea what you expect as a result...

1 like
Fajar's avatar
Level 2

@ftiersch I hope the result is 37 days

carbon :: now () to retrieve the current date
and lastOfMonth () takes the end date in the current month

so what I hope is that I add 7 days to a total of 1 month means I get a total of 37 days

thx for youre support

ftiersch's avatar
ftiersch
Best Answer
Level 28

Do you need the number of days between to dates?!

"toDateString" reformats the date, it doesn't give you a number. You need intervals for that.

now()->lastOfMonth()->addDays(7)->diffInDays(now()->firstOfMonth())
Fajar's avatar
Level 2

@ftiersch thx for youre answer

now()->lastOfMonth()->addDays(7)->diffInDays(now()->firstOfMonth())

i get this

36
``

so I made it 8 to get 37 days

now()->lastOfMonth()->addDays(7)->diffInDays(now()->firstOfMonth())


and i get this

37

Please or to participate in this conversation.