Is there something built into PHP to convert seconds to days, hours, mins?

php

Solution

function secondsToWords($seconds)
{
    $ret = "";

    /*** get the days ***/
    $days = intval(intval($seconds) / (3600*24));
    if($days> 0)
    {
        $ret .= "$days days ";
    }

    /*** get the hours ***/
    $hours = (intval($seconds) / 3600) % 24;
    if($hours > 0)
    {
        $ret .= "$hours hours ";
    }

    /*** get the minutes ***/
    $minutes = (intval($seconds) / 60) % 60;
    if($minutes > 0)
    {
        $ret .= "$minutes minutes ";
    }

    /*** get the seconds ***/
    $seconds = intval($seconds) % 60;
    if ($seconds > 0) {
        $ret .= "$seconds seconds";
    }

    return $ret;
}

print secondsToWords(3744000);

Problem

For example if I have: ``` $seconds = 3744000; // i want to output: 43 days, 8 hours, 0 minutes ``` Do I have to create a function to convert this? Or does PHP already have something built in to do this like `date()`?

Original source

Related problems