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
->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.
@ftiersch
for first youre code i get this
"2019-11-30"
if i try this
Carbon::now()
->lastOfMonth()
->addDays(7)
->toDateString();
i get this
"2019-10-07"
Yes... Sorry but I have no idea what you expect as a result...
@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
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())
@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.