Timestamps

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Pazuzu156
Forum Contributor
Posts: 241
Joined: Sat Nov 20, 2010 9:00 pm
Location: GA, USA
Contact:

Timestamps

Post 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?
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Timestamps

Post 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');
Post Reply