Page 1 of 1

Timestamps

Posted: Wed Nov 16, 2011 3:01 pm
by Pazuzu156
I'm making an online test that checks to see how long it took someone to take that test. When they begin, a timestamp is created, once they finish, a new one is created. How can I take the two timestamps and echo that out to say how long it took them to take the test?

Re: Timestamps

Posted: Wed Nov 16, 2011 3:13 pm
by Celauran

Code: Select all

$start = date('Y-m-d H:i:s', time() - (5 * 60 * 60));
$end   = date('Y-m-d H:i:s', time());

$startTime = new DateTime($start);
$endTime   = new DateTime($end);
$diff      = $endTime->diff($startTime);

echo $diff->format('%H:%I:%S');