Yogirajsinh Jethwa Yogirajsinh Jethwa - 28 days ago 21
PHP Question

PHP Minutes to hours and minutes


  • Is there any function I pass minutes and returns hours and minutes in PHP?

  • I have tried mktime function but not working more than 24 hours see bellow example

    echo date('H:i', mktime(0,257));


Answer

Try this one

function hour_min($minutes){// Total
    return sprintf("%02d",floor($minutes / 60)).':'.sprintf("%02d",str_pad(($minutes % 60), 2, "0", STR_PAD_LEFT));
}
echo hour_min(500);

this will return output : 08:20