Jump to content

Difference(Datetime) Averages


jakzodiac

Recommended Posts

First off...Hi everyone, I'm hoping you all can help.

 

I'm working on a script that stores datetimes of users logging in and out of a system. I've found out how to get the time the user was logged in using the following code.

 



$q = "SELECT * FROM VISITOR WHERE MONTH(timeIn)=MONTH(NOW()) ORDER BY id";
$monthsVisitors = mysql_query($q);

while($row = mysql_fetch_array($monthsVisitors)) {
 $timeIn = $row['timeIn'];
 $timeOut = $row['timeOut'];
 $timeDiff = dateDiff($timeOut, $timeIn);
}

 

Assuming I store hundreds of entries in the "Visitor" table, with each row containing a "timeIn" and "timeOut". What would be the best way to get an average of "$timeDiff"?

Link to comment
https://forums.phpfreaks.com/topic/269737-differencedatetime-averages/
Share on other sites

Okay, that worked. It returns the following.

 

1337870.6667

 

When the query returns this value, can it be formatted? I tried to apply different datetime formats and couldn't get any to work. Is this because it is returned as a variable?

 

Lastly, thank you for the help so far. Way more helpful than stackexchange. They kept turning down my questions.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.