Jump to content

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"?

Edited by jakzodiac
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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.