Convert mysql date to days hours minutes seconds

I have this query:

SELECT timediff(stop_time,start_time) as total from `work`;
which gives me this

239:53:36

where 239 is hours, 53 is minutes and 36 is seconds.

Instead, I want it to 9 days 5 hours, 53 minutes etc

I could either do this from mysql or php, though i would prefer to do it from mysql.

I have mysql version 5.0.11 running on suse sles 9
LVL 1
revo1059Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

darron_chapmanCommented:
This is how you would do it in PHP...

<?php
$total="239:35:36";
list($hours,$minutes,$seconds)=explode(":",$total);
echo floor($hours/24)." days ".($hours%24)." minutes ".$seconds." seconds.";
?>
0
darron_chapmanCommented:
whoops, this should be right
<?php
$total="239:35:36";
list($hours,$minutes,$seconds)=explode(":",$total);
echo floor($hours/24)." days ".($hours%24)." hours ".$minutes." minutes ".$seconds." seconds.";
?>
0
revo1059Author Commented:
Any idea how to do it in mysql?  I have played with all the date functions, but can never seem to get it quite right.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

darron_chapmanCommented:
Hope this works for you:
SELECT concat( truncate( hour( timediff(stop_time,start_time) ) /24, 0 ) , " days ", hour( timediff(stop_time,start_time) ) %24, " hours ", minute( timediff(stop_time,start_time) ) , " minutes ", second( timediff(stop_time,start_time) ) , " seconds" ) as total from `work`;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
revo1059Author Commented:
That is exactly perfect.  Thank you so much.
0
revo1059Author Commented:
sorry for such a long delay.  I didn't realize that I had not accepted the answer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.