"This was done X minutes ago" code generated with timestamp?

Discussion in 'PHP' started by mynameisdi, Mar 1, 2009.

  1. #1
    Hey guys,

    So I have a timestamp that goes something like 1219169855 -- that

    What I need is to create a php string that would transform that timestamp into

    "User did this XX minutes ago"

    Googling didn't help much, so how can I do that?

    I've got this in my php code

    <?

    $data = mysql_query("SELECT * FROM gg_event ORDER BY id DESC LIMIT 20");
    while($row = mysql_fetch_array($data))
    {

    echo "


    .$row[client_abr]. [I want the timestamp to be here]







    ";

    }


    ?>

    .$row[timestamp]. would be the call for the timestamp.

    How do I transform it into "XX minutes ago" ?

    I've got an extra $2 in my paypal to anyone whos advice actually helps
     
    mynameisdi, Mar 1, 2009 IP
  2. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Let's assume your timestamp is in $row[timestamp].

    
    // time() is the call for the current timestamp.
    $currtime = time();
    $timesince = $currtime - $row['timestamp'];
    // It's currently in seconds. Let's put it into minutes.
    $timesince = $timesince / 60;
    // $timesince is now your time since last action.
    echo 'This was done' . $timesince . ' minutes ago';
    
    PHP:
     
    qualityfirst, Mar 1, 2009 IP
  3. mynameisdi

    mynameisdi Banned

    Messages:
    977
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <?
    // time() is the call for the current timestamp.
    $currtime = time();
    $timesince = $currtime - $row['timestamp'];
    // It's currently in seconds. Let's put it into minutes.
    $timesince = $timesince / 60;
    // $timesince is now your time since last action.
    // Create a connection to your database.

    // Query database and select the last 10 entries.
    $data = mysql_query("SELECT * FROM gg_event WHERE user_id='{$id}' ORDER BY id DESC LIMIT 25");
    while($row = mysql_fetch_array($data))



    {

    echo "

    ".$row[client_name]."

    'This was done' . $timesince . ' minutes ago'
    <br>

    Is this correct?

    If it is, it doesn't work.

    go 'This was done' . 205....0667 . ' minutes ago'

    This is what it shows up :( the timestrap is cloaked by skype





    ";

    }


    ?>
    </div>
     
    mynameisdi, Mar 1, 2009 IP
  4. Pos1tron

    Pos1tron Peon

    Messages:
    95
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0