Results 1 to 3 of 3

Thread: [RESOLVED] Unix TimeStamp / Mysql Timestamp and Time() Usage?

  1. #1
    Join Date
    Oct 2006

    resolved [RESOLVED] Unix TimeStamp / Mysql Timestamp and Time() Usage?

    Hi i think this is a simple question really might not be though, anyway im trying to use the following code to echo offline/crashed if the time stamp is over 5 minutes old but when i tried this code on a timestamp only 50 seconds old and one 18 hours old they both echoed offline. Did i do somthing wrong?

    function convert_datetime($str) 
    	list($date, $time) = explode(' ', $str);
    	list($year, $month, $day) = explode('-', $date);
    	list($hour, $minute, $second) = explode(':', $time);
    	$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
    	return $timestamp;
    if (convert_datetime($GetCharsrow['cur_timestamp']) < (time() - 5))
             echo "Crashed/Offline";
    Any help is greatly appreciated.

    - Sam

  2. #2
    Join Date
    Dec 2005
    time()-5 gives the timestamp of 5 seconds ago. You want time()-300

    It is important to understand how you're inserting/getting your date-time field into/from the database. Because time() defaults to a unix timestamp, the timestamp that you get out of the database must be a unixtimestamp as well. The best way to do this is to make your query as below:

    select UNIX_TIMESTAMP(cur_timestamp) from `mytable`;
    That also allows you to do a direct comparison to time, instead of running the result through another function:

    PHP Code:
    if($GetCharsrow['UNIX_TIMESTAMP(cur_timestamp)'] < (time()-300)) {

    Last edited by aj_nsc; 02-28-2010 at 08:17 AM.
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...

  3. #3
    Join Date
    Oct 2006
    Thank you i will give it a go.

    EDIT: That didnt seem to work showed everything as offline even if it was updated only seconds ago.

    This is how im getting the data

    $GetCharsQuery = "SELECT * FROM rrstats WHERE ID = '$USERid'";
    $GetChars = mysql_query($GetCharsQuery) or die ("didn't query");
    while($GetCharsrow = mysql_fetch_array($GetChars))
           Here is like a big long series of echos including the one i put in the first post.
    EDIT2: ahhh nevermind i got it to work thanks for your help again.
    Last edited by lilsammy; 02-28-2010 at 09:04 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Recent Articles