PHP使用小时和分钟减去日期

Hi I've search the internet about this topics and seems can't give me the right ouput? What could I be doing doing wrong? I want to output the remaining days from an expiration period with hours and minutes.

Here's what I've done,

$date_expire = '2014-09-12 23:59:59';  
$date = new DateTime($date_expire);
$now =  new DateTime();
echo $date->diff($now)->format("%d days, %H hours and %i minutes");

I am from the philippines and the current date and time I wrote this is August 13, 2014 5:26pm the ouput gives me 29 days, 12 hours and 30 minutes. Which is think is wrong? Can you help me? thanks!

your source code is working fine and it does what you expect.

yes, on that date was missed 29 days 12 hours and 30 minutes and a few months.

the problem is that you don't print out the months (:

here, there is your script with the months included:

// this is your start date
$date_expire = "2014-09-12 23:59:59";
// build a DateTime instance from it
$date = new DateTime($date_expire);
// another instance for the date of NOW
$now =  new DateTime();
// print the difference with %m (months) included
echo $date->diff($now)->format("%m months, %d days, %H hours and %i minutes");

For reference, the %a is the way to go. Here combined with a simple check on whether some subscription has expired or not.

date_default_timezone_set('Asia/Manila');

// August 13, 2014 5:26pm
$date_now    = '2014-08-13 17:26:00';
$date_expire = '2014-09-12 23:59:59';

$now     = new DateTime($date_now);
$expires = new DateTime($date_expire);

$diff = $expires->diff($now)->format("%a days, %h hours and %i minutes");

if ($now < $expires) {
    echo "Your subscription will expire in $diff", PHP_EOL;
} else {
    echo "Your subscription expired $diff ago", PHP_EOL;
}

Output:

Your subscription will expire in 30 days, 6 hours and 33 minutes

Running it today, with $now = new DateTime(); this output is given:

Your subscription expired 168 days, 2 hours and 56 minutes ago