Tikky Tikky -4 years ago 78
PHP Question

How to convert minutes to hours and minutes (without days)

I would like to display time in minues as an hour and minutes.

Example 1: I want to display 125 minutes as a 2:05

I know I can to somethink like:

$converted_time = date('H:i', mktime(0,$minutes);

This works fine, but if the time is more then 24h it is a problem.

Example 2:


and I want to receive 25:10 (without days), only hours and minutes.

How to do that?

Answer Source

You can use:


$hours = intdiv($minutes, 60).':'. ($minutes % 60);

Previous answer:


$hours = floor($minutes / 60).':'.($minutes -   floor($minutes / 60) * 60);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download