Reputation: 3209
In my laravel project, I want to increase the date time with the previous date time.
Here is my code
$expire=$order[0]->expire_date;
$new=Carbon::now()->addMonths(6);
The results of these two lines are
2018-01-28 21:23:56
2018-06-28 21:43:29
What I want to do is sum the both dates.
$expire+$new
How can I achieve this? Any idea or thought? Thanks.
Edit with more clear view
I want to find the remaining days of the expire date from now
and then want to add this remaining date with the new date. Hope it clears.
Upvotes: 4
Views: 10053
Reputation: 312
you can add something like that:
$new=Carbon::createFromTimestamp($order[0]->expire_date->timestamp)->addMonths(6);
Upvotes: 0
Reputation: 163788
If you want to add six months to order expiration date, just do this:
$new = $order[0]->expire_date->addMonths(6);
This will work since $order[0]->expire_date
is a Carbon instance.
If it's not, just parse it first:
$new = Carbon::parse($order[0]->expire_date)->addMonths(6);
Upvotes: 7