I have put together some code that adds an amount of days on to a date/time. For some reason the first day is calculated as 12 hours. For example, if I set one day it will add 12 hours. If I set 2 days it will add 36 hours.
$postdate = "03/08/2014 14:55:18";
echo $postdate;
//SPLIT UP DATE
$month = substr("$postdate", 0, -17);
$day = substr("$postdate", 3, -14);
$year = substr("$postdate", 6, -9);
$hour = substr("$postdate", 11, -6);
$min = substr("$postdate", 14, -3);
$sec = substr("$postdate", 17);
//DAYS LEFT
$days_left = 1; // Set Days Left
$add_day = "P$days_left D";
$tot_day = preg_replace('/\s+/', '', $add_day); // Trims white space
// Add days
$date = new DateTime();
$date->setDate($year, $month, $day);
$date->setTime($hour, $min, $sec);
$date->add(new DateInterval("$tot_day"));
$end = $date->format("m/d/y h:m:i");
// If time is up
if (time(new DateTimeZone('Europe/London')) > strtotime("$end"))
{
// Times Up
}
else
{
// Time Left
}
?>
Here I have the told the code to add 1 day to the date and time. But my result adds 12 hours instead.
Any help is appreciated. Thanks.