Solved

# Convert secs to time

Posted on 2004-09-14
284 Views
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?
0
Question by:anusha
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 33

Accepted Solution

snoyes_jw earned 50 total points
ID: 12058552
why not just use:

return date("h:i A", strtotime("0:0:" . \$mysec));
0

LVL 33

Expert Comment

ID: 12058568
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
###### Suggested Courses
Course of the Month6 days, 10 hours left to enroll