in reply to Using Timestamp to tell if someone is on the site

How about just unformatted time. ie

my $lasttime=from_db($userid); my $thistime=time; if ($thistime-$lasttime<(5*60)) { print 'online'."\n"; } set_db($userid,$thistime);

Replies are listed 'Best First'.
Re^2: Using Timestamp to tell if someone is on the site
by htmanning (Friar) on Jan 05, 2017 at 05:23 UTC
    Thank you, I figured it out although not as clean as you did. I inserted the date and time into separate database fields. I then split the lastvisittime and multiplied the hour by 60. I added that number to the minutes to get a time in minutes. I did the same for the current time, then subtracted the last visit from now. Thanks.

      What if the last visit was at 23:59, and now is 00:01? The difference is negative which is less than 5 and says online and is right

      But what if the last visit was at 22:59, and now is 00:01? The difference is again negative which is less than 5 and says online, but wrong since it was more than 5 min ago

      Consider calculating the time difference when you select the record. For example in MySQL

      SELECT TIMESTAMPDIFF(SECOND,lastvisit,NOW()) FROM table

      Change SECOND to MINUTE as required.

      poj