revo1059
asked on
Convert mysql date to days hours minutes seconds
I have this query:
SELECT timediff(stop_time,start_t ime) 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
SELECT timediff(stop_time,start_t
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
whoops, this should be right
<?php
$total="239:35:36";
list($hours,$minutes,$seco nds)=explo de(":",$to tal);
echo floor($hours/24)." days ".($hours%24)." hours ".$minutes." minutes ".$seconds." seconds.";
?>
<?php
$total="239:35:36";
list($hours,$minutes,$seco
echo floor($hours/24)." days ".($hours%24)." hours ".$minutes." minutes ".$seconds." seconds.";
?>
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is exactly perfect. Thank you so much.
ASKER
sorry for such a long delay. I didn't realize that I had not accepted the answer
<?php
$total="239:35:36";
list($hours,$minutes,$seco
echo floor($hours/24)." days ".($hours%24)." minutes ".$seconds." seconds.";
?>