Link to home
Start Free TrialLog in
Avatar of revo1059
revo1059Flag for United States of America

asked on

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
Avatar of darron_chapman
darron_chapman
Flag of United States of America image

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.";
?>
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.";
?>
Avatar of revo1059

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of darron_chapman
darron_chapman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That is exactly perfect.  Thank you so much.
sorry for such a long delay.  I didn't realize that I had not accepted the answer