Nowadays I am working on laravel application. I am new on laravel and it is my first project. Can you guys please tell me how to increase days in date?
I have these 3 variables:
$subscription['start_date'] = $dates['start'];
$subscription['end_date'] = $dates['end'];
$subscription['trial_end_date'] = $dates['trial'];
start
end
trial
start values are perfect but in end and trial I want date of 10 days later
Please help me, I'd be really thankful
You can achieve that using the Carbon PHP API date-time exstension.
If you want to add 10 days to your date, simply do this:
$subscription['trial_end_date']->addDays(10);
Or if your trial_end_date
is not a Carbon
instance, you can do this instead:
Carbon::parse($subscription['trial_end_date'])->addDays(10);
The method is the same for any of your dates. If you have any errors or need any more help, let me know.
Make use of Carbon
, where you can easily handles tasks like this.
Example:
$subscription['trial_end_date'] = Carbon::createFromFormat('your-format-here', $dates['trial']);
$subscription['trial_end_date']->addDays(10);
Don't forget to import the correct Namespace on top
Use Carbon\Carbon
$date = $your_desire->addDays($i);
The best way is by using Carbon
. Carbon is a simple php
Api extension for Datetime
.
First you need to import carbon like so use Carbon\Carbon;
which in built in Laravel
.
Make $subscription['start_date']
an instance of Carbon before using addDays()
<?php // Make $subscription['start_date'] an instance of Carbon before using addDays() $trialends = Carbon::parse($subscription['start_date'])->addDays(10);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.