Calculating time spent (time difference) in MySQL/PHP -


i'm developing task management app workplace. able calculate how long took task made, until finished.

pr app log date , time (for instance: 2013-09-28 , 14:42) task created. log date , time task marked completed.

i know can use mysql datediff() calculate amount of days took, i'm wondering how can calculate rest (hours , minutes).

basicly want output says: "this task took 2 days, 4 hours , 30 minutes complete."

anyone have suggestion how can this?

thanks in advance help.

best regards, simen

using datetime: (you want format result better)

    $q = new datetime('2013-10-11 10:10:11');     $w = new datetime('2013-11-18 14:13:16');     $result = $w->diff($q);     $string = "this task took ";     if ($result->y > 0) {$string .= $result->y.' years, ';}     if ($result->m > 0) {$string .= $result->m.' months, ';}     if ($result->d > 0) {$string .= $result->d.' days, ';}     if ($result->h > 0) {$string .= $result->h.' hours, ';}     if ($result->i > 0) {$string .= $result->i.' minutes, ';}     if ($result->s > 0) {$string .= $result->s.' seconds ';}     $string .= "to complete.";     echo $string; 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -