xnowandtheworldx Posted March 30, 2008 Share Posted March 30, 2008 On my website for users to upload their gaming videos, when i'm formatting the seconds into minutes when there is a 0 in the duration for some reason it gets truncated and i've scoured the internet and found nothing.... i've tried (int) and intval() so any help would be greatly appreciated! $mins = floor($duration_first / 60); $secs = $duration_first % 60; $duration = $mins.":".$secs; and then i store it in a table as varchar Link to comment https://forums.phpfreaks.com/topic/98562-php-auto-truncates-my-zeros/ Share on other sites More sharing options...
micah1701 Posted March 30, 2008 Share Posted March 30, 2008 you could also just use gdate() like: $duration = gdate("H:i",strtotime($duration_first)); Link to comment https://forums.phpfreaks.com/topic/98562-php-auto-truncates-my-zeros/#findComment-504437 Share on other sites More sharing options...
doni49 Posted March 30, 2008 Share Posted March 30, 2008 That'll do the time. Here's an example of forcing it to leave the leading zeros (would be useful if you're not working with dates). I thought I'd go ahead and post it anyway seeing as I was already to post it anyway. http://us3.php.net/sprintf $mins = floor($duration_first / 60); $secs = $duration_first % 60; $duration = sprintf("%02d:%02d", $mins, $secs); Link to comment https://forums.phpfreaks.com/topic/98562-php-auto-truncates-my-zeros/#findComment-504440 Share on other sites More sharing options...
xnowandtheworldx Posted March 30, 2008 Author Share Posted March 30, 2008 Thanks for both of those solutions guys! I never even thought of forcing the zeros with the gdate function either, but once again thanks to both of your solutions! Link to comment https://forums.phpfreaks.com/topic/98562-php-auto-truncates-my-zeros/#findComment-504506 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.