Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

    Converting time into seconds

    I had help with making time into seconds, minutes, hours, days. But how does only seconds work? I want to have it where your online within the last 150 seconds (2 1/2 minutes) and Idle for 5 minutes. This coding isn't working for me.

    Code:
     
    $checkquery = doquery('SELECT * FROM {{table}} WHERE UNIX_TIMESTAMP(`onlinetime`) >= ' . (time() - 600) . '', 'accounts');
    while ($checkrow = mysql_fetch_array($checkquery))
    			{
    
    				$activetime = strtotime($checkrow['onlinetime']);
    				$timenow = time();
    				$lastonline = $timenow - $activetime;
    
                                    if ($lastonline <= 150)
    				{
    					$online = "<font color=green><b>Online</b></font>";
    				}
    				elseif ($lastonline <= 300)
    				{
    					$online = "<font color=blue><b>Idle</b></font>";
    				}
    				else
    				{
    					$online = "<font color=red><b>Not Online</b></font>";
    				}

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    That's funny, I made one just this morning:
    PHP Code:
    function sec2time($sec) {
            
    $time '';
            
    $seconds $sec&#37;60;
            
    $minutes $sec 60 60;
            
    $hours $sec 3600 24;
            
    $days intval($sec 86400) ;
            
    $time "$days day(s) $hours:$minutes:$seconds";
            return 
    $time;

    In your script, is $activetime getting set right? Is $checkrow['onlinetime'] coming in right? You've probably already done it, but have you tried printing them each out to make sure that your calculating things with the correct values?
    Last edited by derzok; 08-06-2008 at 04:06 PM.
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Here is what I get when I echo the results.

    Code:
    Online Set: 2008-08-06 09:30:29
    Active Time: 1218036629

  • #4
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    *bump*

  • #5
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Odd - which of the conditionals gets executed? The if, elseif, or the else? Is it always the same one? Also, make sure that you aren't using localized times - ie make sure they are all the same timezone. I've had this issue before when subtracting GM time from an Eastern Standard Time (where I live) and visa-versa. Check them here: http://www.csgnetwork.com/unixds2timecalc.html If time() and the time you get from the database are localized differently...
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    It should be the same time zone, because all the other online functions on the site work. Just this one isn't working. All of them always say the same thing. If I do it normal, it all says Online, when I am the only one online, if I alter the number, it all says Idle. if I comment out the query, it all says Not Online. But I can't get each to work.


  •  

    Posting Permissions

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