Yogirajsinh Jethwa Yogirajsinh Jethwa -4 years ago 222
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download