Re: Minutes to hours/days/monthes/years?
| From: | Jome | Date: | Mon, 18 Nov 2002 06:10:02 +0000 |
| Subject: | Re: Minutes to hours/days/monthes/years? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-124877@lists.php.net to get a copy of this message | ||
> 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=viewCode&ID=88
I do believe that my solution is more efficent, considering that I use
modulus.
Jome