I'm trying to set the time between 2 variables but when I check it copies the change on the 2 time. For example, I select 1:00 and 23:00 , both dates show 23:00 only. I can't seem to get why it's showing like that even if I have already different variables for each time. I need to show the different dates.
Input Dates:
01:30 and 21:00
My code:
$date = $_POST['datepicker'];
$time1 = $_POST['timepicker'];
$time2 = $_POST['timepicker2'];
$time1_array = explode(":",$time1);
$time2_array = explode(":",$time2);
$date = $_POST['datepicker'];
$date = new DateTime($date);
$date2 = $date;
$datefinal1 = date_time_set($date, $time1_array[0], $time1_array[1], 00);
$datefinal2 = date_time_set($date2, $time2_array[0], $time2_array[1], 59);
$result = $datefinal1->format('Y-m-d H:i:s');
$result2 = $datefinal2->format('Y-m-d H:i:s');
print_r($datefinal1);
Sample output that I am getting:
DateTime Object ( [date] => 2015-03-17 21:00:59 [timezone_type] => 3 [timezone] => Europe/Berlin )
even if I should be getting the $datefinal2's value.