Skip to:
Content
Pages
Categories
Search
Top
Bottom

Timestamp help please


  • kirkslater
    Participant

    @kirkslater

    Hi

    I’m using the below code to collect the timestamp of the time an image was uploaded using the BP-Album plugin, but need it to display in the same way that the activity stream displays time elapsed since i.e. “Posted 5 days, 17 hours ago”

    picture->date_uploaded; ?>

    Does anyone know how to convert it?

    I did track down the below but I couldn’t work out how to add the images timestamp to it. Any help would be really appreciated :)

    <?php
    
    $time = strtotime('2010-04-28 17:25:43');
    
    echo 'event happened '.humanTiming($time).' ago';
    
    function humanTiming ($time)
    {
    
    $time = time() - $time; // to get the time since that moment
    
    $tokens = array (
    31536000 => 'year',
    2592000 => 'month',
    604800 => 'week',
    86400 => 'day',
    3600 => 'hour',
    60 => 'minute',
    1 => 'second'
    );
    
    foreach ($tokens as $unit => $text) {
    if ($time < $unit) continue;
    $numberOfUnits = floor($time / $unit);
    return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
    }
    }
    
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)

  • shanebp
    Moderator

    @shanebp

    You probably need to use date_format()

    Something like:

    
    $time = $pictures_template->picture->date_uploaded;
    $time = date_format($time, 'Y-m-d H:i:s');
    echo 'event happened '.humanTiming($time).' ago';
    
    

    Note that BP has a function for this
    bp_core_time_since($time)
    but you’ll need to pass $time as a Unix timestamp.


    kirkslater
    Participant

    @kirkslater

    Thanks for the suggestion @shanebp but it didn’t seem to work. I think its because its missing the globe call for `global $pictures_template;`

    Any ideas how to tie this in?

    Cheers


    shanebp
    Moderator

    @shanebp

    Seriously ?
    Did you try adding the global call ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Timestamp help please’ is closed to new replies.
Skip to toolbar