Convert secs to time

I am trying to write a function to convert seconds to time format (hh:mm AM/PM)


function convertsecs ( $mysec )
{

      $timesec = bcmod($mysec,60);
      $timemin = bcmod(($mysec - $timesec),3600) / 60;
      $timehour = ($mysec - ($timemin*60)) / 3600;
      $newtime = date("h m", mktime($timehour,$timemin));

      return $newtime;
}

Is this right? If not what am I doing wrong?
anushaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
snoyes_jwConnect With a Mentor Commented:
why not just use:

return date("h:i A", strtotime("0:0:" . $mysec));
0
 
snoyes_jwCommented:
Even if your math is right, part of your problem may be that "m" in the date function means month of the year, not minute of the hour.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.