I have a php function to add number of days to input date
function GetDateToReturn($StartDate)
{
$date = $StartDate;
return $date->modify('+2 day');
}
When I call above function
$FromDate = date_create('1-Feb-2012');
echo ' From : ' . $FromDate->format('Y-m-d); //From : 2012-02-01
$ToDate = $this->GetDateToReturn($FromDate);
echo ' From : ' . $FromDate->format('Y-m-d'); //From : 2012-02-03
echo ' To : ' . $ToDate->format('Y-m-d'); //To : 2012-02-03
It also changes the value of the input variable?
How to retain the FromDate variable value and get new date to ToDate variable?
Try cloning it: