-2

I want to find difference between these two date with days,hours and minutes.

$date1 = "27-09-2014 05:00 AM";
$date2 = "29-09-2014 03:00 PM";
Gowri
  • 1,832
  • 3
  • 29
  • 53
  • Ref : http://php.net/manual/en/datetime.diff.php – Vinod VT Sep 26 '14 at 11:13
  • possible duplicate of [How to get time difference in minutes in PHP](http://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php) – user2314737 Sep 26 '14 at 11:14
  • Don't worry I can help you, here is the link where you can tae help http://php.net/manual/en/datetime.diff.php read the last topic at the bottom of the page. Hope you will get help :) – Nitin Kaushal Sep 26 '14 at 11:13

2 Answers2

1

From PHP Version > 5 below new date/time functions added to get difference:

$datetime1 = new DateTime("2010-06-20");
$datetime2 = new DateTime("2011-06-22");
$difference = $datetime1->diff($datetime2);

echo 'Difference: '.$difference->y.' years, ' 
                   .$difference->m.' months, ' 
                   .$difference->d.' days';

print_r($difference);

Result as below:

Difference: 1 years, 0 months, 2 days

DateInterval Object
(
    [y] => 1
    [m] => 0
    [d] => 2
    [h] => 0
    [i] => 0
    [s] => 0
    [invert] => 0
    [days] => 367
)
Vidhi
  • 2,026
  • 2
  • 20
  • 31
0

I'm not sure whether I get your question right, but shouldn't the following work?

$datetime1 = new DateTime('27-09-2014');
$datetime2 = new DateTime('29-09-2014');

$datetime1->setTime(05, 00);
$datetime2->setTime(15, 00);


$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%a Day and %h hours'

DateTime::diff

Edi G.
  • 2,432
  • 7
  • 24
  • 33