|
-
Jul 8th, 2005, 05:59 AM
#1
Thread Starter
Addicted Member
Get time difference in minutes
Hey... i have searched for the answer but cannot find what i am looking for so i am turning to you people, hoping i can find out what i need.
Anyway.... I have made a forum and now i am looking to add a feature that lists all the users online at the present time. I am going to acheive this by checking if the 'last active time' is less than 15minutes old. If it is then the user will be classed as online and vice versa.
I just haven't got the foggiest on how to compare the last active time and the current time, and then see if the difference is less than 15 minutes.
Can anybody please help me?? Cheers, BIOSTALL
-
Jul 8th, 2005, 09:00 AM
#2
Fanatic Member
Re: Get time difference in minutes
when the user goes to a page on the forum have it put the current time in the file or database of that user. then use code somthing like this:
PHP Code:
if($timeuserwasonlinelast - 900 <= time()){ // 900 is the number of secs in 15 mins
//do somthing to say user is online
}
-
Jul 10th, 2005, 06:38 AM
#3
Re: Get time difference in minutes
 Originally Posted by ALL
when the user goes to a page on the forum have it put the current time in the file or database of that user. then use code somthing like this:
PHP Code:
if($timeuserwasonlinelast - 900 <= time()){ // 900 is the number of secs in 15 mins
//do somthing to say user is online
}
You need to add the number of seconds to the users last login time. Not subtract them.
PHP Code:
if($timeuserwasonlinelast + 900 <= time()) {
/* last request was less than 15 mins ago */
} else {
/* last request was more than 15 mins ago */
}
You can also find the difference:
PHP Code:
if(time() - $timeuserwasonlinelast <= 900) {
/* last request was less than 15 mins ago */
} else {
/* last request was greater than 15 mins ago */
}
As an extra note, the time() function returns the number of seconds which have elapsed since 1st January 1970 00:00. So you can use basic arithmetic to find the difference between two dates and add dates together.
-
Jul 10th, 2005, 09:36 AM
#4
Fanatic Member
Re: Get time difference in minutes
 Originally Posted by visualAd
You need to add the number of seconds to the users last login time. Not subtract them.
PHP Code:
if($timeuserwasonlinelast + 900 <= time()) {
/* last request was less than 15 mins ago */
} else {
/* last request was more than 15 mins ago */
}
You can also find the difference:
PHP Code:
if(time() - $timeuserwasonlinelast <= 900) {
/* last request was less than 15 mins ago */
} else {
/* last request was greater than 15 mins ago */
}
As an extra note, the time() function returns the number of seconds which have elapsed since 1st January 1970 00:00. So you can use basic arithmetic to find the difference between two dates and add dates together.
well, i accedently hit the subtract key, i ment to say "+"
thanks visad,
-ALL
Last edited by ALL; Jul 10th, 2005 at 11:35 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|