I am creating some dates with Carbon in PHP, but I seem to be doing something wrong.
This here is my code:
$start = Carbon::create(2015, rand(6,7), rand(1,30), 0);
$end = $start->addWeeks(3);
echo "start time: " . $start;
echo "<br />";
echo "end time: " . $end;
And the output of the above is two exact same dates, e.g.:
start time: 2015-07-01 00:00:00
end time: 2015-07-01 00:00:00
I reffered to the docs, which can be found here: http://carbon.nesbot.com/docs/#api-addsub. Does anybody know what am I doing wrong?
addWeeks()
might return$start
(modified) for method chaining. Thus$start === $end
– YggdrasiladdWeek()
work? I'd test myself, but don't have access to Carbon. Also, I'd confirm if the PHP version is sufficient and any dependencies are up-to-date.The home page says 1.x is compatible with PHP 5.3+. A 2.x version is in the works and will require PHP 5.4+. – Croakecho "start time: " . $start;
to before theaddWeeks
line. This will tell you whether the operation succeeded. It might be that some Carbon functions modify the caller, as opposed to returning a new object. Some of the PHP array functions do that. – Croak