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
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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.