I have a total seconds value in my table but I would like to get a time format like hh:mm:ss
,
currently I have for example: seconds - 226
and I know that should be in time format 4 minutes and 26 seconds, but I've tried this code:
$seconds = 226;
$hours = floor($seconds / 3600);
$mins = floor(($seconds - ($hours*3600)) / 60);
$secs = floor(($seconds - ($hours*3600)) - ($mins*60));
and this outputs 3:46
maybe there's something wrong with the formula?
EDIT: I got this value from a youtube scripts that returns duration of video:
$ytvidid = $url;
$ytdataurl = "http://gdata.youtube.com/feeds/api/videos/". $ytvidid;
$feedURL = $ytdataurl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $feedURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// get the result of http query
$output = curl_exec($ch);
curl_close($ch);
// feed the curl output to simplexml_load_string
$sxml = simplexml_load_string($output) or die("XML string not loading");
//$sxml = simplexml_load_file($feedURL);
$media = $sxml->children('http://search.yahoo.com/mrss/');
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
echo $attrs['seconds'];