Support » Plugin: Display Tweets » Can date and time be displayed as time since tweet?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author MatthewRuddy


    Going to work on adding this 🙂



    You can use this function and then on 589 on displaytweets.php

    $posted_since = apply_filters( 'displaytweets_posted_since', humanTiming(date(strtotime( $tweet->created_at ))) );

    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':'');
    Plugin Author MatthewRuddy


    Awesome, that’s much simpler than what I would have done. Didn’t know WordPress had a humanTiming function!

    Thanks a million! 🙂

    This works, thanks.

    Plugin Author MatthewRuddy


    Just to let you’s know, in v1.0.3 (just released) I’ve added an additional filter for modifying the date/time format string. For example, you could do so with the PHP function below.

    function tweet_datetime_string($string) {
        return "l M j \- g:ia";
    add_filter( 'displaytweets_datetime_format', 'tweet_datetime_string' );


    Is it possible to remove the time from the display and display just the date, in DD/MM/YYYY style?


    EDIT: Worked out how to make this change.

    In displaytweets.php, replace lines 601 with the following:

    /** Set the date and time format */
                    $datetime_format = apply_filters( 'displaytweets_datetime_format', "j F Y" );

    I also wanted to pull the date back up to the previous line to conserve screen space, so replaced line 612 with the following

    echo "<p>{$this->format_tweet( $tweet->text )}<small class=\"muted\">  ({$posted_since})</small></p>";
    Plugin Author MatthewRuddy



    function tweet_datetime_string($string) {
        return "d/m";
    add_filter( 'displaytweets_datetime_format', 'tweet_datetime_string' );

    Might have to fiddle around with the date/time string yourself. Have a look here for more info.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Can date and time be displayed as time since tweet?’ is closed to new replies.