如何在php中查找2个日期之间的时差

I want to get the time difference between 2 dates in minutes. The 2 dates are in the following format

date1='05-11-2012 11:25:00'
date2='06-11-2012 17:45:00'
$datetime1 = new DateTime('05-11-2012 11:25:00');
$datetime2 = new DateTime('06-11-2012 17:45:00');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days'); //return +1 days
//or
$datetime1 = date_create('05-11-2012 11:25:00');
$datetime2 = date_create('06-11-2012 17:45:00');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%a days'); //return +1 days

for php <5.3

$date1 = '05-11-2012 11:25:00';
$date2 = '06-11-2012 17:45:00';
$diff = floor(abs( strtotime( $date1 ) - strtotime( $date2 ) )/(60*60*24));
printf("%d days
", $diff); //return 1 days
<?php
$datetime1 = date_create('2009-10-11');
$datetime2 = date_create('2009-10-13');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%a days');
?>

For further reference please visit the following link http://php.net/manual/en/datetime.diff.php

You neglected to indicate what format you'd like the time difference expressed in. If you're willing to work in seconds (which are easily converted), you could simply convert each date to a timestamp and then take the absolute difference using basic math. For instance, give $date1 = '05-11-2012 11:25:00' and $date2 = '06-11-2012 17:45:00':

$diff_seconds = abs( strtotime( $date1 ) - strtotime( $date2 ) );

And you could do whatever you like with the result.

$start_time = strtotime( "2012-10-12 11:35:00" );

$end_time = strtotime( "2012-10-13 12:42:50" );

echo round ( abs( $end_time - $start_time ) / 60,2 ). " minute";

This is different between two dates in MINUTES.