Link to home
Start Free TrialLog in
Avatar of Pedro Chagas
Pedro ChagasFlag for Portugal

asked on

Php - Compare data and time and output the difference

Hi E's, I need to know how I compare two times and output th difference between them.
In practice I have two time, compose by the day and the hours:
$old_time = "2012-09-20";
$old_hour = "23:10:57"; //(hour:minutes:seconds)
$actual_time = "2012-09-21";
$actual_hour = "13:17:44"; //(hour:minutes:seconds)
$difference = "days:hours:minutes:seconds"; //difference between old time and actual time

How I get the result of $difference variable?

The best regards, JC
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

$t1 = strtotime($old_time . ' ' . $old_hour);
$t2 = strtotime($actual_time . ' ' . $actual_hour);
$difference = $t2 - $t1;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial