how to calculate hours,minutes and seconds from total minutes in php? -
i developing 1 website in php.
i need add jobs sql server 2008 database.
i taking job duration in minutes , want convert in h:i:s format.
i using code :
$hours = (int)($duration / 60); $minutes = $duration - ($hours * 60); $time = $hours.":".$minutes;
it works fine int duration 30,60,100,120 etc.
but if duration 1.33 or 5.40 output should 00:01:30 or 00:05:40 respectively.
how can ?
try this
<?php $duration = "1.33"; $hours = (int)($duration / 60); $minutes = $duration - ($hours * 60); date_default_timezone_set('utc'); $date = new datetime($hours.":".$minutes); echo $date->format('h:i:s'); ?>
output
00:01:33
Comments
Post a Comment