Click to See Complete Forum and Search --> : PHP/MYSQL datetime sum


tripwater
07-09-2003, 03:09 PM
Hello I have a table that stores a start and a stop time. They are both datetime.

I am running a project tracker that allows the developer to click a link to start their time then click the stop link to insert the stop time to track the time spent on the project.

I am trying to display the total of the time logged so far for any given task but the method I am using sometimes gives a result and other times gives me something that makes absolutley no sense. Here is my query : BTW the fields are Start & Stop.


$query = " select EXTRACT(HOUR from sum(Stop - Start)) as Hours, EXTRACT(MINUTE from sum(Stop-Start)) as Minutes from dates where
PID = taskid;


$result = @mysql_query($query);

$time = @mysql_fetch_array($result,MYSQL_ASSOC);



then for the displaying of the results :

if (is_null($time["Hours"]))
$hour = 0;
else
$hour = $time["Hours"];


if (is_null($time["Minutes"]))
$minutes = 0;
else
$minutes = $time["Minutes"];

$value.= "<b>Time Logged :</b> ".$hour." hr(s) ".$minutes." min(s)

The end result is I need to get the total hours and the total minutes to display them out of a group of datetimes.

Thank you for any help with this. Like I said some results come back that do not make sense so my display code does not work. If there is another function I could use please let me know. Thanks again.