I am trying to change the time value of a variable using ->setTime in php however I also want to preserve the original time value in a separate variable. Unfortunately when I change one variable it also changes the other. Any ideas?
<?php
//creating a DateTime object
$date = new DateTime("20-May-2015");
$date2 = $date;
echo $date->format("d-M-Y H:i:s") . "\n";
echo $date2->format("d-M-Y H:i:s") . "\n";
echo "\n";
//setting time to a new value
$date->setTime(5, 10);
echo $date->format("d-M-Y H:i:s") . "\n";
echo $date2->format("d-M-Y H:i:s") . "\n";
?>
output
20-May-2015 00:00:00
20-May-2015 00:00:00
20-May-2015 05:10:00
20-May-2015 05:10:00 ***I want this one to stay 20-May-2015 00:00:00***