[PHP] Re: Minutes to hours/days/monthes/years?

2002-11-17 Thread OrangeHairedBoy
OK...I wrote this...is this what you want?


return english_time(64925149);

function english_time($minutes)
{
while ($minutes=525600) {$years++;$minutes-=525600;}
while ($minutes=1440) {$days++;$minutes-=1440;}
while ($minutes=60) {$hours++;$minutes-=60;}
if ($years) { $string[] = ( $years == 1) ? 1 year : $years years; }
if ($days) { $string[] = ( $days == 1) ? 1 day : $days days; }
if ($hours) { $string[] = ( $hours == 1) ? 1 hour : $hours hours; }
if ($minutes) { $string[] = ( $minutes == 1) ? 1 minute : $minutes
minutes; }
return implode(, ,$string);
}



Leif K-Brooks [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 I'm looking for a good way to convert minutes to hours, days, or years -
 the largest it will fit into.  For example, 120 would become 2 hours.
  90 would become 1 hour and 30 minutes.  Any ideas?

 --
 The above message is encrypted with double rot13 encoding.  Any
unauthorized attempt to decrypt it will be prosecuted to the full extent of
the law.





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Minutes to hours/days/monthes/years?

2002-11-17 Thread Jome
 OK...I wrote this...is this what you want?


 return english_time(64925149);

 function english_time($minutes)
 {
 while ($minutes=525600) {$years++;$minutes-=525600;}
 while ($minutes=1440) {$days++;$minutes-=1440;}
 while ($minutes=60) {$hours++;$minutes-=60;}
 if ($years) { $string[] = ( $years == 1) ? 1 year : $years years; }
 if ($days) { $string[] = ( $days == 1) ? 1 day : $days days; }
 if ($hours) { $string[] = ( $hours == 1) ? 1 hour : $hours hours; }
 if ($minutes) { $string[] = ( $minutes == 1) ? 1 minute : $minutes
 minutes; }
 return implode(, ,$string);
 }

I wrote a solution to the same problem, available at
http://www.phpcoded.com/?DO=viewCodeID=88

I do believe that my solution is more efficent, considering that I use
modulus.

   Jome



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php