Results 1 to 4 of 4

Thread: Get time difference in minutes

  1. #1

    Thread Starter
    Addicted Member BIOSTALL's Avatar
    Join Date
    Apr 2005
    Location
    Northampton, UK
    Posts
    180

    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

  2. #2
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    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

    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Get time difference in minutes

    Quote 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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: Get time difference in minutes

    Quote 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.
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width