I'm comparing two DateTime :
//Get the current DateTime
$date_now = new DateTime;
var_dump($date_now); // 2014-03-10 19:04:29
// I need to subtract 12 hours (I'm using $date_past to fetch $db_date in a request)
$date_past = $date_now->sub(new DateInterval("PT12H"));
// Get the DateTime from $db_date just fetched in database
$alert_date = new DateTime($db_date);
var_dump($alert_date); // 2014-03-10 17:04:00 in my test
// Get the difference
$diff = $alert_date->diff($date_now);
var_dump($diff->format("%H:%I:%S")); //09:59:31
So I get 09:59:31 and also $diff->invert == 1 which means that it's a negative value.
I saw this issue : php datetime->diff is calcualting wrong amount of hours (3 too much) and I think it's similar problem but I can't find a solution to keep using ->sub(). Any ideas ?
If you think it could be a TimeZone problem, I checked all my DateTime and they all have a TimeZone set to "Europe/Berlin", so I don't think it come from here.
Thank you !