#### Archived

This topic is now archived and is closed to further replies.

# Seconds to Minutes

## Recommended Posts

I know how to do this in Java, but it seems to be different in PHP.

I have a given number of seconds. Say 140. I want to display it as 2:20.

##### Share on other sites
try
[code]\$sec = 140;

\$min = floor(\$sec/60);
\$sec = \$sec % 60;

printf ('%0d:%02d', \$min, \$sec);[/code]

##### Share on other sites
Well it is truncating the tenths and hundreths of a second. I want to be able to display the decimals.

##### Share on other sites
Where are the tenths and hundredths in "140"?

##### Share on other sites
There are none, that was just an example. Use 101.11 as an example then. I need it to at least go to hundreths.

Thanks

##### Share on other sites
As an example it wasn't very representative. Now I have to answer your question twice :-/

[code]\$secs = 101.11;

\$mins = floor(\$secs/60);

\$secs -= \$mins*60;

printf ('%0d:%02.2f', \$mins, \$secs);[/code]

##### Share on other sites
Well it is working, but when the seconds are less than ten, it doesn't display the zero. For 4:04.86, it displays 4:4.86.

##### Share on other sites
Odd. I tested with

[code]\$secs = 120.11;

\$mins = floor(\$secs/60);

\$secs -= \$mins*60;

printf ('%0d:%02.2f', \$mins, \$secs);[/code]

and got --> 2:00.11

##### Share on other sites
Hmm... well thanks for your help. I'll just have to fiddle with it I guess.