Re: [PHP-WIN] [PHP] Time formatting from int (seconds)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Paul,

Try this out.


function duration($amount)
{
 $seconds = $amount % 60;
 if ($seconds < 10) { $seconds = "0".$seconds; }
 $minutes = (($amount - $seconds) / 60) % 60;
 if ($minutes < 10) { $minutes = "0".$minutes; }
 $hours = ($amount - ($minutes * 60) - $seconds) / 3600;
 $duration = $hours.":".$minutes.":".$seconds;
 echo $duration;
}

duration($nameofvariableholdingsecondshere);

The if statements are just to pretty it up and put some leading 0's in if
needed.  If you didn't want to actually echo it, you could modify it to
return the values instead, which you can then manipulate however you needed
to.  There may be an even more streamlined way, but I just came up with
that, so there ya go. :)

(V)

----- Original Message ----- 
From: "Paul Menard" <paulmenard1@yahoo.com>
> Quick question about the best (and easiest) way to
> format a display string into the HH:MM:SS format from
> an integer var.
>
> Is there a PHP function that will provide this? I've
> looked at the various functions and all are used for
> taking a date/time as use. Or is there a function
> someone has written and would like to share it?
>
> In my case I have the result of a subtraction of two
> date in which seconds are returned as in 980 seconds,
> 576 seconds etc. To make this readable to the user of
> the web page and so they do not need to mentally
> calculate the HHMMSS.



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


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux