So I have function that takes in the start date of an event and the number of days its running for, and it then (should) add those days to the start date to produce an end date. Then I can return the results to my view, e.g.
Start date: 12-06-2015
Length: 4 days
End date: 16-06-2015
Output 12th - 16th June 2015
Here's the function:
function dateCalculator($date,$length)
{
$startDate = $date;
$endDate = $date->addDays($length);
if ($length > 0){
return $dateString = $startDate->format('jS').' - '.$endDate->format('jS F Y');
} else {
return $dateString = '<span>'.$startDate->format('jS F Y').'</span>';
}
}
I don't think I'm adding the days correctly. I'm not getting any errors, but it simply outputs the end date the same as the start date. I have included Carbon at the top of my file.
That's great but on a side note, you shouldn't have received that error if you are passing in the correct data to begin with. In my opinion, createFromFormat is better as you can validate the input.