Level 14
Like this:
$new_date = $start->copy()->addDays(5);
21 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I would like to get +few days of an existing Carbon instance. However I don't wont to change existing instance so this is not an option:
<?php
// $start is an instance of Carbon
$new_date = $start->addDays(5)
// now $start points 5 days ahead
How to do it without modyfing old instance?
Like this:
$new_date = $start->copy()->addDays(5);
Please or to participate in this conversation.