Re: How to count time in php

From: Date: Mon, 22 Jan 2001 22:24:26 +0000
Subject: Re: How to count time in php
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-36104@lists.php.net to get a copy of this message
> can anybody help me how to count seconds, minutes and hours in php? > I want to sum values like 03:35, 02:31, 04:59, etc. and show the > results in minutes. Here's how I would try to do it: <?php $times = array("03:35", "02:31", "04:59"); $hours = 0; $minutes = 0; $seconds = 0; while (list(,$time) = each($times)){ $minsec = explode(':', $time); $minutes += $minsec[0]; $seconds += $minsec[1]; } $minutes += (int) ($seconds/60); $seconds = $seconds % 60; $hours = (int) ($minutes/60); $minutes = $minutes % 60; if ($hours){ echo "$hours hours, "; } echo "$minutes minutes, $seconds seconds<BR>\n"; ?> There's probably several other ways to do it. YMMV. Don't miss the Zend Web Store's Grand Opening on January 23, 2001! http://www.zend.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#36104) next »