Jump to content

milliseconds to min:sec


The Little Guy

Recommended Posts

I have a duration column in my database, which looks like this:

256574.69387755

 

it holds the duration of a song, how do I convert that number to a time? I am not sure what the time comes out to but I would like it formated:

 

min:sec

 

example:

4:10

 

how would I convert that? to get the minutes I thought I could do this:

 

$min = $row['duration'] % 60;

 

but that doesn't work any suggestions on how to get the minutes and the seconds?

Link to comment
https://forums.phpfreaks.com/topic/212734-milliseconds-to-minsec/
Share on other sites

Try this:

 

print "Duration: " . floor($row['duration'] / 60) . ":" . floor($row['duration'] % 60);

 

If your values really are in around 250k in size, you might need to divide by 1000 as well to get the values you want.

 

Edit: Just re-read your question properly.  Try this:

 

print "Duration: " . floor($row['duration'] / 60000) . ":" . floor(($row['duration'] / 1000) % 60);

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.