$d1 = new DateTime('11:00:00');
$d2 = new DateTime('04:00:00');

$diff = $d1->diff($d2);

echo $diff->h, " hours ", $diff->i, " minutes\n";

Output:

7 hours 0 minutes

 Compare dates:

$st_dt = new DateTime(verifyParam ('start_date'));
$end_dt = new DateTime(verifyParam ('end_date'));

// is the end date more ancient than the start date?
if ($end_dt < $start_dt) 

You can also compare epoch seconds :

$d1->format('U') < $d2->format('U')

http://www.stoimen.com/blog/2011/11/04/how-to-check-if-a-date-is-more-or-less-than-a-month-ago-with-php/

Advertisements