Calculating time differences.
| From: | Mike Eheler | Date: | Tue, 16 Oct 2001 23:37:34 +0000 |
| Subject: | Calculating time differences. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-71273@lists.php.net to get a copy of this message | ||
If I have two times, in text format:
14:32:23 and 17:56:36
How can I calculate the difference between the two, and have it returned like:
03:24:13
Then beyond that, once I have a bunch of these differences, such as:
03:24:13
00:45:52
etc
I need be able to add those all up as I go, so it'd be a loop and it'd keep a running total.
The numerical equivalent of what I want to do is:
$total = 0;
while ($data = mysql_fetch_array($result)) {
$difference = $data['end'] - $data['start']; // for example, (end = 5) - (start = 3)
echo $difference; // 2
$total += $difference;
}
echo $total;
Mike